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 = {
    
    
    delivery_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    project: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'planned',
    
    
    
    
    
    
    
    
    
    
    
    
    planned_ship_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    planned_delivery_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivered_at: '',
    
    
    
    
    
    
    
    
    
    
    
    ship_to_address: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    carrier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tracking_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shipping_cost: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    proof_of_delivery: [],
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const DeliveriesNew = () => {
  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('/deliveries/deliveries-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    planned_ship_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    planned_delivery_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : initialValues
                
            }
            onSubmit={(values) => handleSubmit(values)}
          >
            <Form>



  <FormField
      label="DeliveryNumber"
  >
      <Field
          name="delivery_number"
          placeholder="DeliveryNumber"
      />
  </FormField>













































  <FormField label="Project" labelFor="project">
      <Field name="project" id="project" component={SelectField} options={[]} itemRef={'projects'}></Field>
  </FormField>























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























  <FormField
      label="PlannedShipAt"
  >
      <Field
          type="datetime-local"
          name="planned_ship_at"
          placeholder="PlannedShipAt"
      />
  </FormField>



























  <FormField
      label="PlannedDeliveryAt"
  >
      <Field
          type="datetime-local"
          name="planned_delivery_at"
          placeholder="PlannedDeliveryAt"
      />
  </FormField>



























  <FormField
      label="DeliveredAt"
  >
      <Field
          type="datetime-local"
          name="delivered_at"
          placeholder="DeliveredAt"
      />
  </FormField>



















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

























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



























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

































    <FormField
        label="ShippingCost"
    >
        <Field
            type="number"
            name="shipping_cost"
            placeholder="ShippingCost"
        />
    </FormField>












































  <FormField>
      <Field
          label='ProofofDelivery'
          color='info'
          icon={mdiUpload}
          path={'deliveries/proof_of_delivery'}
          name='proof_of_delivery'
          id='proof_of_delivery'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormFilePicker}
      ></Field>
  </FormField>






    <FormField label="Notes" hasTextareaHeight>
        <Field name="notes" as="textarea" placeholder="Notes" />
    </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
