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: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    customer: '',
    
    
    
    
    
    
    
    
    
    shipped_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipment_status: 'planned',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    from_location: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipped_by: '',
    
    
    
    
    carrier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tracking_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    attachments: [],
    
    
    
    
    
}


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



















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































  <FormField label="ShipmentStatus" labelFor="shipment_status">
      <Field name="shipment_status" id="shipment_status" component="select">
      
        <option value="planned">planned</option>
      
        <option value="packed">packed</option>
      
        <option value="shipped">shipped</option>
      
        <option value="delivered">delivered</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>































  <FormField label="FromLocation" labelFor="from_location">
      <Field name="from_location" id="from_location" component={SelectField} options={[]} itemRef={'locations'}></Field>
  </FormField>



























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









  <FormField
      label="Carrier"
  >
      <Field
          name="carrier"
          placeholder="Carrier"
      />
  </FormField>



























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





























    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </FormField>
















































  <FormField>
      <Field
          label='Attachments'
          color='info'
          icon={mdiUpload}
          path={'shipments/attachments'}
          name='attachments'
          id='attachments'
          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
