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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    type: 'TRUCK',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'ACTIVE',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    ownership: 'OWNED',
    
    
    
    
    
    
    
    plate_number: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vin: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    brand: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    model: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    variant: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    year: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    first_registration_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fuel_type: 'DIESEL',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    emission_class: 'EURO_3',
    
    
    
    
    
    
    
    
    
    
    gross_weight_kg: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    curb_weight_kg: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    payload_kg: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    axle_count: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    has_liftgate: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tachograph_type: 'ANALOG',
    
    
    
    
    
    
    
    tachograph_serial: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tachograph_last_calibration_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    tachograph_next_calibration_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    toll_provider: 'TOLL_COLLECT',
    
    
    
    
    
    
    
    toll_obu_serial: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    toll_contract_no: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    insurance_notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    photo: [],
    
    
    
    
}


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

    
    

  const handleSubmit = async (data) => {
    await dispatch(create(data))
    await router.push('/vehicles/vehicles-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="VehicleType" labelFor="type">
      <Field name="type" id="type" component="select">
      
        <option value="TRUCK">TRUCK</option>
      
        <option value="TRACTOR">TRACTOR</option>
      
        <option value="VAN">VAN</option>
      
        <option value="CAR">CAR</option>
      
        <option value="BUS">BUS</option>
      
        <option value="OTHER">OTHER</option>
      
      </Field>
  </FormField>



























  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="ACTIVE">ACTIVE</option>
      
        <option value="INACTIVE">INACTIVE</option>
      
        <option value="SOLD">SOLD</option>
      
        <option value="SCRAPPED">SCRAPPED</option>
      
        <option value="SUSPENDED">SUSPENDED</option>
      
      </Field>
  </FormField>



























  <FormField label="Ownership" labelFor="ownership">
      <Field name="ownership" id="ownership" component="select">
      
        <option value="OWNED">OWNED</option>
      
        <option value="LEASED">LEASED</option>
      
        <option value="RENTED">RENTED</option>
      
      </Field>
  </FormField>













  <FormField
      label="PlateNumber"
  >
      <Field
          name="plate_number"
          placeholder="PlateNumber"
      />
  </FormField>



























  <FormField
      label="VIN"
  >
      <Field
          name="vin"
          placeholder="VIN"
      />
  </FormField>



























  <FormField
      label="Brand"
  >
      <Field
          name="brand"
          placeholder="Brand"
      />
  </FormField>



























  <FormField
      label="Model"
  >
      <Field
          name="model"
          placeholder="Model"
      />
  </FormField>



























  <FormField
      label="Variant"
  >
      <Field
          name="variant"
          placeholder="Variant"
      />
  </FormField>

































    <FormField
        label="Year"
    >
        <Field
            type="number"
            name="year"
            placeholder="Year"
        />
    </FormField>































  <FormField
      label="FirstRegistrationAt"
  >
      <Field
          type="datetime-local"
          name="first_registration_at"
          placeholder="FirstRegistrationAt"
      />
  </FormField>































  <FormField label="FuelType" labelFor="fuel_type">
      <Field name="fuel_type" id="fuel_type" component="select">
      
        <option value="DIESEL">DIESEL</option>
      
        <option value="LNG">LNG</option>
      
        <option value="CNG">CNG</option>
      
        <option value="ELECTRIC">ELECTRIC</option>
      
        <option value="HYBRID">HYBRID</option>
      
        <option value="OTHER">OTHER</option>
      
      </Field>
  </FormField>



























  <FormField label="EmissionClass" labelFor="emission_class">
      <Field name="emission_class" id="emission_class" component="select">
      
        <option value="EURO_3">EURO_3</option>
      
        <option value="EURO_4">EURO_4</option>
      
        <option value="EURO_5">EURO_5</option>
      
        <option value="EURO_6">EURO_6</option>
      
        <option value="OTHER">OTHER</option>
      
      </Field>
  </FormField>



















    <FormField
        label="GrossWeight(kg)"
    >
        <Field
            type="number"
            name="gross_weight_kg"
            placeholder="GrossWeight(kg)"
        />
    </FormField>



























    <FormField
        label="CurbWeight(kg)"
    >
        <Field
            type="number"
            name="curb_weight_kg"
            placeholder="CurbWeight(kg)"
        />
    </FormField>



























    <FormField
        label="Payload(kg)"
    >
        <Field
            type="number"
            name="payload_kg"
            placeholder="Payload(kg)"
        />
    </FormField>



























    <FormField
        label="AxleCount"
    >
        <Field
            type="number"
            name="axle_count"
            placeholder="AxleCount"
        />
    </FormField>





































  <FormField label='HasLiftgate' labelFor='has_liftgate'>
      <Field
          name='has_liftgate'
          id='has_liftgate'
          component={SwitchField}
      ></Field>
  </FormField>

























  <FormField label="TachographType" labelFor="tachograph_type">
      <Field name="tachograph_type" id="tachograph_type" component="select">
      
        <option value="ANALOG">ANALOG</option>
      
        <option value="DIGITAL">DIGITAL</option>
      
        <option value="SMART_1">SMART_1</option>
      
        <option value="SMART_2">SMART_2</option>
      
        <option value="OTHER">OTHER</option>
      
      </Field>
  </FormField>













  <FormField
      label="TachographSerial"
  >
      <Field
          name="tachograph_serial"
          placeholder="TachographSerial"
      />
  </FormField>





































  <FormField
      label="TachographLastCalibrationAt"
  >
      <Field
          type="datetime-local"
          name="tachograph_last_calibration_at"
          placeholder="TachographLastCalibrationAt"
      />
  </FormField>



























  <FormField
      label="TachographNextCalibrationAt"
  >
      <Field
          type="datetime-local"
          name="tachograph_next_calibration_at"
          placeholder="TachographNextCalibrationAt"
      />
  </FormField>































  <FormField label="TollProvider" labelFor="toll_provider">
      <Field name="toll_provider" id="toll_provider" component="select">
      
        <option value="TOLL_COLLECT">TOLL_COLLECT</option>
      
        <option value="OTHER">OTHER</option>
      
      </Field>
  </FormField>













  <FormField
      label="TollOBUSerial"
  >
      <Field
          name="toll_obu_serial"
          placeholder="TollOBUSerial"
      />
  </FormField>



























  <FormField
      label="TollContractNo"
  >
      <Field
          name="toll_contract_no"
          placeholder="TollContractNo"
      />
  </FormField>





























    <FormField label="InsuranceNotes" hasTextareaHeight>
        <Field name="insurance_notes" as="textarea" placeholder="InsuranceNotes" />
    </FormField>



























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















































  <FormField>
      <Field
          label='Photo'
          color='info'
          icon={mdiUpload}
          path={'vehicles/photo'}
          name='photo'
          id='photo'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></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('/vehicles/vehicles-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default VehiclesNew
