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: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    branch: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    category: '',
    
    
    
    
    display_name: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    make: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    model: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    year_label: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vin: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    license_plate: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    status: 'available',
    
    
    
    
    
    
    
    
    
    
    odometer_km: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    fuel_policy: 'full_to_full',
    
    
    
    
    
    
    
    color: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    photos: [],
    
    
    
    
    
    
    features: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    next_service_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    is_listed: false,
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    organizations: '',
    
    
    
}


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



























  <FormField label="Category" labelFor="category">
      <Field name="category" id="category" component={SelectField} options={[]} itemRef={'vehicle_categories'}></Field>
  </FormField>









  <FormField
      label="DisplayName"
  >
      <Field
          name="display_name"
          placeholder="DisplayName"
      />
  </FormField>



























  <FormField
      label="Make"
  >
      <Field
          name="make"
          placeholder="Make"
      />
  </FormField>



























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



























  <FormField
      label="Year"
  >
      <Field
          name="year_label"
          placeholder="Year"
      />
  </FormField>



























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



























  <FormField
      label="LicensePlate"
  >
      <Field
          name="license_plate"
          placeholder="LicensePlate"
      />
  </FormField>









































  <FormField label="Status" labelFor="status">
      <Field name="status" id="status" component="select">
      
        <option value="available">available</option>
      
        <option value="reserved">reserved</option>
      
        <option value="rented">rented</option>
      
        <option value="maintenance">maintenance</option>
      
        <option value="inactive">inactive</option>
      
      </Field>
  </FormField>



















    <FormField
        label="Odometer(km)"
    >
        <Field
            type="number"
            name="odometer_km"
            placeholder="Odometer(km)"
        />
    </FormField>



































  <FormField label="FuelPolicy" labelFor="fuel_policy">
      <Field name="fuel_policy" id="fuel_policy" component="select">
      
        <option value="full_to_full">full_to_full</option>
      
        <option value="same_to_same">same_to_same</option>
      
        <option value="prepurchase">prepurchase</option>
      
        <option value="free_tank">free_tank</option>
      
      </Field>
  </FormField>













  <FormField
      label="Color"
  >
      <Field
          name="color"
          placeholder="Color"
      />
  </FormField>

















































  <FormField>
      <Field
          label='Photos'
          color='info'
          icon={mdiUpload}
          path={'vehicles/photos'}
          name='photos'
          id='photos'
          schema={{
            size: undefined,
            formats: undefined,
          }}
          component={FormImagePicker}
      ></Field>
  </FormField>







    <FormField label="Features" hasTextareaHeight>
        <Field name="features" as="textarea" placeholder="Features" />
    </FormField>



































  <FormField
      label="NextServiceAt"
  >
      <Field
          type="datetime-local"
          name="next_service_at"
          placeholder="NextServiceAt"
      />
  </FormField>

































  <FormField label='IsListed' labelFor='is_listed'>
      <Field
          name='is_listed'
          id='is_listed'
          component={SwitchField}
      ></Field>
  </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('/vehicles/vehicles-list')}/>
              </BaseButtons>
            </Form>
          </Formik>
        </CardBox>
      </SectionMain>
    </>
  )
}

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

export default VehiclesNew
