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/vehicle_categories/vehicle_categoriesSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";


const Vehicle_categoriesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { vehicle_categories } = useAppSelector((state) => state.vehicle_categories)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

    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 vehicle_categories')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View vehicle_categories')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/vehicle_categories/vehicle_categories-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CategoryName</p>
                    <p>{vehicle_categories?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Transmission</p>
                    <p>{vehicle_categories?.transmission ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

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

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Seats</p>
                  <p>{vehicle_categories?.seats || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Doors</p>
                  <p>{vehicle_categories?.doors || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>LargeBags</p>
                  <p>{vehicle_categories?.large_bags || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SmallBags</p>
                  <p>{vehicle_categories?.small_bags || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='HasAirConditioning'>
                    <SwitchField
                      field={{name: 'has_air_conditioning', value: vehicle_categories?.has_air_conditioning}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vehicles Category</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>DisplayName</th>
                                
                                
                                
                                <th>Make</th>
                                
                                
                                
                                <th>Model</th>
                                
                                
                                
                                <th>Year</th>
                                
                                
                                
                                <th>VIN</th>
                                
                                
                                
                                <th>LicensePlate</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Odometer(km)</th>
                                
                                
                                
                                <th>FuelPolicy</th>
                                
                                
                                
                                <th>Color</th>
                                
                                
                                
                                
                                
                                <th>Features</th>
                                
                                
                                
                                <th>NextServiceAt</th>
                                
                                
                                
                                <th>IsListed</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicle_categories.vehicles_category && Array.isArray(vehicle_categories.vehicles_category) &&
                              vehicle_categories.vehicles_category.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vehicles/vehicles-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="display_name">
                                        { item.display_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="make">
                                        { item.make }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="model">
                                        { item.model }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="year_label">
                                        { item.year_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="vin">
                                        { item.vin }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_plate">
                                        { item.license_plate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="odometer_km">
                                        { item.odometer_km }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="fuel_policy">
                                        { item.fuel_policy }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="color">
                                        { item.color }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="features">
                                        { item.features }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="next_service_at">
                                        { dataFormatter.dateTimeFormatter(item.next_service_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_listed">
                                        { dataFormatter.booleanFormatter(item.is_listed) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicle_categories?.vehicles_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Rate_rules VehicleCategory</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>StartAt</th>
                                
                                
                                
                                <th>EndAt</th>
                                
                                
                                
                                <th>DayType</th>
                                
                                
                                
                                <th>RateOverride</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {vehicle_categories.rate_rules_category && Array.isArray(vehicle_categories.rate_rules_category) &&
                              vehicle_categories.rate_rules_category.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/rate_rules/rate_rules-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="start_at">
                                        { dataFormatter.dateTimeFormatter(item.start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_at">
                                        { dataFormatter.dateTimeFormatter(item.end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="day_type">
                                        { item.day_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rate_override">
                                        { item.rate_override }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!vehicle_categories?.rate_rules_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Vehicle_categoriesView;