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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    trip_no: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'PLANNED',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    dispatcher_user: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    driver: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vehicle: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    trailer: '',
    
    
    
    
    
    
    
    
    
    planned_start_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    planned_end_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    started_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    finished_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    start_odometer_km: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    end_odometer_km: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    distance_km: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/trips/trips-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="Company" labelFor="company">
      <Field name="company" id="company" component={SelectField} options={[]} itemRef={'companies'}></Field>
  </FormField>









  <FormField
      label="TripNo"
  >
      <Field
          name="trip_no"
          placeholder="TripNo"
      />
  </FormField>









































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="PLANNED">PLANNED</option>
      
        <option value="DISPATCHED">DISPATCHED</option>
      
        <option value="IN_PROGRESS">IN_PROGRESS</option>
      
        <option value="COMPLETED">COMPLETED</option>
      
        <option value="CANCELLED">CANCELLED</option>
      
      </Field>
  </FormField>































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



























  <FormField label="Driver" labelFor="driver">
      <Field name="driver" id="driver" component={SelectField} options={[]} itemRef={'employees'}></Field>
  </FormField>



























  <FormField label="Vehicle" labelFor="vehicle">
      <Field name="vehicle" id="vehicle" component={SelectField} options={[]} itemRef={'vehicles'}></Field>
  </FormField>



























  <FormField label="Trailer" labelFor="trailer">
      <Field name="trailer" id="trailer" component={SelectField} options={[]} itemRef={'trailers'}></Field>
  </FormField>



















  <FormField
      label="PlannedStartAt"
  >
      <Field
          type="datetime-local"
          name="planned_start_at"
          placeholder="PlannedStartAt"
      />
  </FormField>



























  <FormField
      label="PlannedEndAt"
  >
      <Field
          type="datetime-local"
          name="planned_end_at"
          placeholder="PlannedEndAt"
      />
  </FormField>



























  <FormField
      label="StartedAt"
  >
      <Field
          type="datetime-local"
          name="started_at"
          placeholder="StartedAt"
      />
  </FormField>



























  <FormField
      label="FinishedAt"
  >
      <Field
          type="datetime-local"
          name="finished_at"
          placeholder="FinishedAt"
      />
  </FormField>























    <FormField
        label="StartOdometer(km)"
    >
        <Field
            type="number"
            name="start_odometer_km"
            placeholder="StartOdometer(km)"
        />
    </FormField>



























    <FormField
        label="EndOdometer(km)"
    >
        <Field
            type="number"
            name="end_odometer_km"
            placeholder="EndOdometer(km)"
        />
    </FormField>



























    <FormField
        label="Distance(km)"
    >
        <Field
            type="number"
            name="distance_km"
            placeholder="Distance(km)"
        />
    </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('/trips/trips-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default TripsNew
