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

const initialValues = {
    
    
    
    
    
    
    
    
    
    
    
    
    
    company: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    vehicle: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    trailer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    type: 'HU',
    
    
    
    
    
    
    
    issuer: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    report_no: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    performed_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    expires_at: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    passed: false,
    
    
    
    
    
    
    
    
    
    
    
    
    odometer_km: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
    notes: '',
    
    
    
    
    
    
    
    
    
    
    
    
    
}


const Vehicle_inspectionsNew = () => {
  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('/vehicle_inspections/vehicle_inspections-list')
  }
  return (
    <>
      <Head>
        <title>{getPageTitle('New Item')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="New Item" main>
        {''}
        </SectionTitleLineWithButton>
        <CardBox>
          <Formik
            initialValues={
                
                
                
                dateRangeStart && dateRangeEnd ?
                {
                    ...initialValues,
                    performed_at: moment(dateRangeStart).format('YYYY-MM-DDTHH:mm'),
                    expires_at: moment(dateRangeEnd).format('YYYY-MM-DDTHH:mm'),
                } : 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="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="InspectionType" labelFor="type">
      <Field name="type" id="type" component="select">
      
        <option value="HU">HU</option>
      
        <option value="AU">AU</option>
      
        <option value="UVV">UVV</option>
      
        <option value="SP">SP</option>
      
        <option value="ADR_VEHICLE">ADR_VEHICLE</option>
      
        <option value="LIFTGATE">LIFTGATE</option>
      
        <option value="TAIL_LIFT">TAIL_LIFT</option>
      
        <option value="OTHER">OTHER</option>
      
      </Field>
  </FormField>













  <FormField
      label="Issuer"
  >
      <Field
          name="issuer"
          placeholder="Issuer"
      />
  </FormField>



























  <FormField
      label="ReportNo"
  >
      <Field
          name="report_no"
          placeholder="ReportNo"
      />
  </FormField>





































  <FormField
      label="PerformedAt"
  >
      <Field
          type="datetime-local"
          name="performed_at"
          placeholder="PerformedAt"
      />
  </FormField>



























  <FormField
      label="ExpiresAt"
  >
      <Field
          type="datetime-local"
          name="expires_at"
          placeholder="ExpiresAt"
      />
  </FormField>

































  <FormField label='Passed' labelFor='passed'>
      <Field
          name='passed'
          id='passed'
          component={SwitchField}
      ></Field>
  </FormField>

















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

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

export default Vehicle_inspectionsNew
