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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    carrier: '',
    
    
    
    
    tracking_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'label_created',
    
    
    
    
    
    
    
    
    
    
    
    
    shipped_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivered_at: '',
    
    
    
    
    
    
    
    
    
    
    shipping_cost_iqd: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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

    
    
    // get from url params
    const { dateRangeStart, dateRangeEnd } = router.query
    

  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={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    shipped_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    delivered_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>





















  <FormField label="Order" labelFor="order">
      <Field name="order" id="order" component={SelectField} options={[]} itemRef={'orders'}></Field>
  </FormField>



























  <FormField label="Carrier" labelFor="carrier">
      <Field name="carrier" id="carrier" component={SelectField} options={[]} itemRef={'shipping_carriers'}></Field>
  </FormField>









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









































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="label_created">label_created</option>
      
        <option value="in_transit">in_transit</option>
      
        <option value="out_for_delivery">out_for_delivery</option>
      
        <option value="delivered">delivered</option>
      
        <option value="failed">failed</option>
      
        <option value="returned">returned</option>
      
      </Field>
  </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="ShippingCost(IQD)"
    >
        <Field
            type="number"
            name="shipping_cost_iqd"
            placeholder="ShippingCost(IQD)"
        />
    </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
