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

const initialValues = {
    
    
    shipment_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    sales_order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'packed',
    
    
    
    
    
    
    
    
    
    
    
    
    packed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipped_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivered_at: '',
    
    
    
    
    
    
    
    
    
    
    carrier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tracking_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    from_warehouse: '',
    
    
    
    
    
    ship_to_address: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipped_by: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    documents: [],
    
    
    
    
    
}


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

    
    

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













































  <FormField label="SalesOrder" labelFor="sales_order">
      <Field name="sales_order" id="sales_order" component={SelectField} options={[]} itemRef={'sales_orders'}></Field>
  </FormField>























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="packed">packed</option>
      
        <option value="shipped">shipped</option>
      
        <option value="delivered">delivered</option>
      
        <option value="returned">returned</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>























  <FormField
      label="PackedAt"
  >
      <Field
          type="datetime-local"
          name="packed_at"
          placeholder="PackedAt"
      />
  </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="Carrier"
  >
      <Field
          name="carrier"
          placeholder="Carrier"
      />
  </FormField>



























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













































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











    <FormField label="ShipToAddress" hasTextareaHeight>
        <Field name="ship_to_address" as="textarea" placeholder="ShipToAddress" />
    </FormField>











































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
































  <FormField>
      <Field
          label='Documents'
          color='info'
          icon={mdiUpload}
          path={'shipments/documents'}
          name='documents'
          id='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('/shipments/shipments-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default ShipmentsNew
