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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    purchase_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    store: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivery_status: 'scheduled',
    
    
    
    
    
    
    
    
    
    
    
    
    departed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    arrived_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    received_by_employee: '',
    
    
    
    
    
    
    delivery_note: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivery_documents: [],
    
    
    
    
    
}


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

    
    

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



























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























  <FormField label="DeliveryStatus" labelFor="delivery_status">
      <Field name="delivery_status" id="delivery_status" component="select">
      
        <option value="scheduled">scheduled</option>
      
        <option value="in_transit">in_transit</option>
      
        <option value="arrived">arrived</option>
      
        <option value="unloaded">unloaded</option>
      
        <option value="checked_in">checked_in</option>
      
        <option value="returned">returned</option>
      
      </Field>
  </FormField>























  <FormField
      label="DepartedAt"
  >
      <Field
          type="datetime-local"
          name="departed_at"
          placeholder="DepartedAt"
      />
  </FormField>



























  <FormField
      label="ArrivedAt"
  >
      <Field
          type="datetime-local"
          name="arrived_at"
          placeholder="ArrivedAt"
      />
  </FormField>



































  <FormField label="ReceivedByEmployee" labelFor="received_by_employee">
      <Field name="received_by_employee" id="received_by_employee" component={SelectField} options={[]} itemRef={'employees'}></Field>
  </FormField>













      <FormField label='DeliveryNote' hasTextareaHeight>
          <Field
              name='delivery_note'
              id='delivery_note'
              component={RichTextField}
          ></Field>
      </FormField>














































  <FormField>
      <Field
          label='DeliveryDocuments'
          color='info'
          icon={mdiUpload}
          path={'deliveries/delivery_documents'}
          name='delivery_documents'
          id='delivery_documents'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></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('/deliveries/deliveries-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default DeliveriesNew
