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 = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    order: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    courier: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivery_status: 'pending_assignment',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivery_mode: 'walking',
    
    
    
    
    
    
    
    pickup_latitude: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pickup_longitude: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    dropoff_latitude: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    dropoff_longitude: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    distance_km: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    courier_earnings: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    platform_commission: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    assigned_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    picked_up_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    delivered_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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,
                    assigned_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="Courier" labelFor="courier">
      <Field name="courier" id="courier" component={SelectField} options={[]} itemRef={'users'}></Field>
  </FormField>























  <FormField label="DeliveryStatus" labelFor="delivery_status">
      <Field name="delivery_status" id="delivery_status" component="select">
      
        <option value="pending_assignment">pending_assignment</option>
      
        <option value="assigned">assigned</option>
      
        <option value="picked_up">picked_up</option>
      
        <option value="in_transit">in_transit</option>
      
        <option value="delivered">delivered</option>
      
        <option value="failed">failed</option>
      
        <option value="cancelled">cancelled</option>
      
      </Field>
  </FormField>



























  <FormField label="DeliveryMode" labelFor="delivery_mode">
      <Field name="delivery_mode" id="delivery_mode" component="select">
      
        <option value="walking">walking</option>
      
        <option value="bicycle">bicycle</option>
      
        <option value="motorbike">motorbike</option>
      
        <option value="car">car</option>
      
        <option value="van">van</option>
      
      </Field>
  </FormField>



















    <FormField
        label="PickupLatitude"
    >
        <Field
            type="number"
            name="pickup_latitude"
            placeholder="PickupLatitude"
        />
    </FormField>



























    <FormField
        label="PickupLongitude"
    >
        <Field
            type="number"
            name="pickup_longitude"
            placeholder="PickupLongitude"
        />
    </FormField>



























    <FormField
        label="DropoffLatitude"
    >
        <Field
            type="number"
            name="dropoff_latitude"
            placeholder="DropoffLatitude"
        />
    </FormField>



























    <FormField
        label="DropoffLongitude"
    >
        <Field
            type="number"
            name="dropoff_longitude"
            placeholder="DropoffLongitude"
        />
    </FormField>



























    <FormField
        label="DistanceKm"
    >
        <Field
            type="number"
            name="distance_km"
            placeholder="DistanceKm"
        />
    </FormField>



























    <FormField
        label="CourierEarnings"
    >
        <Field
            type="number"
            name="courier_earnings"
            placeholder="CourierEarnings"
        />
    </FormField>



























    <FormField
        label="PlatformCommission"
    >
        <Field
            type="number"
            name="platform_commission"
            placeholder="PlatformCommission"
        />
    </FormField>































  <FormField
      label="AssignedAt"
  >
      <Field
          type="datetime-local"
          name="assigned_at"
          placeholder="AssignedAt"
      />
  </FormField>



























  <FormField
      label="PickedUpAt"
  >
      <Field
          type="datetime-local"
          name="picked_up_at"
          placeholder="PickedUpAt"
      />
  </FormField>



























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



































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