import React, { ReactElement, useEffect } from 'react';
import Head from 'next/head'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
import {useRouter} from "next/router";
import { fetch } from '../../stores/vehicles/vehiclesSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";


const VehiclesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { vehicles } = useAppSelector((state) => state.vehicles)
    

    const { id } = router.query;
    
    function removeLastCharacter(str) {
      console.log(str,`str`)
      return str.slice(0, -1);
    }

    useEffect(() => {
        dispatch(fetch({ id }));
    }, [dispatch, id]);


    return (
      <>
          <Head>
              <title>{getPageTitle('View vehicles')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View vehicles')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/vehicles/vehicles-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Company</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{vehicles?.company?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>VehicleType</p>
                    <p>{vehicles?.type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Status</p>
                    <p>{vehicles?.status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Ownership</p>
                    <p>{vehicles?.ownership ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PlateNumber</p>
                    <p>{vehicles?.plate_number}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>VIN</p>
                    <p>{vehicles?.vin}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Brand</p>
                    <p>{vehicles?.brand}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Model</p>
                    <p>{vehicles?.model}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Variant</p>
                    <p>{vehicles?.variant}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Year</p>
                  <p>{vehicles?.year || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='FirstRegistrationAt'>
                    {vehicles.first_registration_at ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={vehicles.first_registration_at ?
                        new Date(
                          dayjs(vehicles.first_registration_at).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No FirstRegistrationAt</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>FuelType</p>
                    <p>{vehicles?.fuel_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>EmissionClass</p>
                    <p>{vehicles?.emission_class ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>GrossWeight(kg)</p>
                  <p>{vehicles?.gross_weight_kg || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>CurbWeight(kg)</p>
                  <p>{vehicles?.curb_weight_kg || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Payload(kg)</p>
                  <p>{vehicles?.payload_kg || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>AxleCount</p>
                  <p>{vehicles?.axle_count || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='HasLiftgate'>
                    <SwitchField
                      field={{name: 'has_liftgate', value: vehicles?.has_liftgate}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TachographType</p>
                    <p>{vehicles?.tachograph_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TachographSerial</p>
                    <p>{vehicles?.tachograph_serial}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='TachographLastCalibrationAt'>
                    {vehicles.tachograph_last_calibration_at ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={vehicles.tachograph_last_calibration_at ?
                        new Date(
                          dayjs(vehicles.tachograph_last_calibration_at).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No TachographLastCalibrationAt</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='TachographNextCalibrationAt'>
                    {vehicles.tachograph_next_calibration_at ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={vehicles.tachograph_next_calibration_at ?
                        new Date(
                          dayjs(vehicles.tachograph_next_calibration_at).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No TachographNextCalibrationAt</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TollProvider</p>
                    <p>{vehicles?.toll_provider ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TollOBUSerial</p>
                    <p>{vehicles?.toll_obu_serial}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TollContractNo</p>
                    <p>{vehicles?.toll_contract_no}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={vehicles?.insurance_notes} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={vehicles?.notes} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Photo</p>
                    {vehicles?.photo?.length
                      ? (
                        <ImageField
                          name={'photo'}
                          image={vehicles?.photo}
                          className='w-20 h-20'
                        />
                      ) : <p>No Photo</p>
                    }
                </div>
              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicle_trailer_links Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>LinkedFrom</th>
                                
                                
                                
                                <th>LinkedTo</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.vehicle_trailer_links_vehicle && Array.isArray(vehicles.vehicle_trailer_links_vehicle) &&
                              vehicles.vehicle_trailer_links_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicle_trailer_links/vehicle_trailer_links-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="linked_from">
                                        { dataFormatter.dateTimeFormatter(item.linked_from) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="linked_to">
                                        { dataFormatter.dateTimeFormatter(item.linked_to) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.vehicle_trailer_links_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicle_inspections Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>InspectionType</th>
                                
                                
                                
                                <th>Issuer</th>
                                
                                
                                
                                <th>ReportNo</th>
                                
                                
                                
                                <th>PerformedAt</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>Passed</th>
                                
                                
                                
                                <th>Odometer(km)</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.vehicle_inspections_vehicle && Array.isArray(vehicles.vehicle_inspections_vehicle) &&
                              vehicles.vehicle_inspections_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicle_inspections/vehicle_inspections-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="type">
                                        { item.type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="issuer">
                                        { item.issuer }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="report_no">
                                        { item.report_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="performed_at">
                                        { dataFormatter.dateTimeFormatter(item.performed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="passed">
                                        { dataFormatter.booleanFormatter(item.passed) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="odometer_km">
                                        { item.odometer_km }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.vehicle_inspections_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicle_maintenances Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>MaintenanceType</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>WorkshopName</th>
                                
                                
                                
                                <th>WorkshopContact</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>FinishedAt</th>
                                
                                
                                
                                <th>Odometer(km)</th>
                                
                                
                                
                                <th>CostAmount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.vehicle_maintenances_vehicle && Array.isArray(vehicles.vehicle_maintenances_vehicle) &&
                              vehicles.vehicle_maintenances_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicle_maintenances/vehicle_maintenances-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="type">
                                        { item.type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="workshop_name">
                                        { item.workshop_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="workshop_contact">
                                        { item.workshop_contact }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="finished_at">
                                        { dataFormatter.dateTimeFormatter(item.finished_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="odometer_km">
                                        { item.odometer_km }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cost_amount">
                                        { item.cost_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.vehicle_maintenances_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicle_insurances Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>InsuranceType</th>
                                
                                
                                
                                <th>Provider</th>
                                
                                
                                
                                <th>PolicyNumber</th>
                                
                                
                                
                                <th>Broker</th>
                                
                                
                                
                                <th>CoverageAmount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>ValidFrom</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                <th>Active</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.vehicle_insurances_vehicle && Array.isArray(vehicles.vehicle_insurances_vehicle) &&
                              vehicles.vehicle_insurances_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicle_insurances/vehicle_insurances-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="type">
                                        { item.type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider">
                                        { item.provider }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="policy_number">
                                        { item.policy_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="broker">
                                        { item.broker }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="coverage_amount">
                                        { item.coverage_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="valid_from">
                                        { dataFormatter.dateTimeFormatter(item.valid_from) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.vehicle_insurances_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicle_documents Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>DocumentType</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.vehicle_documents_vehicle && Array.isArray(vehicles.vehicle_documents_vehicle) &&
                              vehicles.vehicle_documents_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicle_documents/vehicle_documents-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="type">
                                        { item.type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.vehicle_documents_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Driver_vehicle_assignments Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>AssignedFrom</th>
                                
                                
                                
                                <th>AssignedTo</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.driver_vehicle_assignments_vehicle && Array.isArray(vehicles.driver_vehicle_assignments_vehicle) &&
                              vehicles.driver_vehicle_assignments_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/driver_vehicle_assignments/driver_vehicle_assignments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="assigned_from">
                                        { dataFormatter.dateTimeFormatter(item.assigned_from) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="assigned_to">
                                        { dataFormatter.dateTimeFormatter(item.assigned_to) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.driver_vehicle_assignments_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Trips Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>TripNo</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>PlannedStartAt</th>
                                
                                
                                
                                <th>PlannedEndAt</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>FinishedAt</th>
                                
                                
                                
                                <th>StartOdometer(km)</th>
                                
                                
                                
                                <th>EndOdometer(km)</th>
                                
                                
                                
                                <th>Distance(km)</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.trips_vehicle && Array.isArray(vehicles.trips_vehicle) &&
                              vehicles.trips_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/trips/trips-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="trip_no">
                                        { item.trip_no }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="planned_start_at">
                                        { dataFormatter.dateTimeFormatter(item.planned_start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="planned_end_at">
                                        { dataFormatter.dateTimeFormatter(item.planned_end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="finished_at">
                                        { dataFormatter.dateTimeFormatter(item.finished_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="start_odometer_km">
                                        { item.start_odometer_km }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_odometer_km">
                                        { item.end_odometer_km }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="distance_km">
                                        { item.distance_km }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.trips_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Cost_items Vehicle</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Category</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>OccurredAt</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>Vendor(FreeText)</th>
                                
                                
                                
                                <th>Reference</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicles.cost_items_vehicle && Array.isArray(vehicles.cost_items_vehicle) &&
                              vehicles.cost_items_vehicle.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/cost_items/cost_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="occurred_at">
                                        { dataFormatter.dateTimeFormatter(item.occurred_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vendor">
                                        { item.vendor }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reference">
                                        { item.reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicles?.cost_items_vehicle?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                

                <BaseDivider />

                <BaseButton
                    color='info'
                    label='Back'
                    onClick={() => router.push('/vehicles/vehicles-list')}
                />
              </CardBox>
          </SectionMain>
      </>
    );
};

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

export default VehiclesView;