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/driver_profiles/driver_profilesSlice'
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 Driver_profilesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { driver_profiles } = useAppSelector((state) => state.driver_profiles)
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Employee</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{driver_profiles?.employee?.last_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Compliance</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{driver_profiles?.compliance?.license_number ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Driver_compliances DriverProfile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>LicenseCountry</th>
                                
                                
                                
                                <th>LicenseNumber</th>
                                
                                
                                
                                <th>LicenseIssuedAt</th>
                                
                                
                                
                                <th>LicenseExpiresAt</th>
                                
                                
                                
                                <th>LicenseRestrictions</th>
                                
                                
                                
                                <th>LicenseSuspended</th>
                                
                                
                                
                                <th>CPCNumber</th>
                                
                                
                                
                                <th>CPCIssuedAt</th>
                                
                                
                                
                                <th>CPCExpiresAt</th>
                                
                                
                                
                                <th>CPCCenter</th>
                                
                                
                                
                                <th>CPCLastTrainingAt</th>
                                
                                
                                
                                <th>CPCNextTrainingAt</th>
                                
                                
                                
                                <th>CPCType</th>
                                
                                
                                
                                <th>ADRNumber</th>
                                
                                
                                
                                <th>ADRExpiresAt</th>
                                
                                
                                
                                <th>ADRTank</th>
                                
                                
                                
                                <th>ADRPackages</th>
                                
                                
                                
                                <th>ADRLastCourseAt</th>
                                
                                
                                
                                <th>ADRNextCourseAt</th>
                                
                                
                                
                                <th>ADRRestrictions</th>
                                
                                
                                
                                <th>MedicalCertificateNumber</th>
                                
                                
                                
                                <th>MedicalIssuedBy</th>
                                
                                
                                
                                <th>MedicalExpiresAt</th>
                                
                                
                                
                                <th>PsychTestNumber</th>
                                
                                
                                
                                <th>PsychExpiresAt</th>
                                
                                
                                
                                <th>EyeExamAt</th>
                                
                                
                                
                                <th>CardioExamAt</th>
                                
                                
                                
                                <th>MedicalRestrictions</th>
                                
                                
                                
                                <th>TachoCardNumber</th>
                                
                                
                                
                                <th>TachoCountry</th>
                                
                                
                                
                                <th>TachoExpiresAt</th>
                                
                                
                                
                                <th>TachoLastDownloadAt</th>
                                
                                
                                
                                <th>TachoNextDownloadAt</th>
                                
                                
                                
                                <th>ViolationsCount</th>
                                
                                
                                
                                <th>WarningsCount</th>
                                
                                
                                
                                <th>DrivingBan</th>
                                
                                
                                
                                <th>DrivingBanUntil</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {driver_profiles.driver_compliances_driver_profile && Array.isArray(driver_profiles.driver_compliances_driver_profile) &&
                              driver_profiles.driver_compliances_driver_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/driver_compliances/driver_compliances-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="license_country">
                                        { item.license_country }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_number">
                                        { item.license_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_issued_at">
                                        { dataFormatter.dateTimeFormatter(item.license_issued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.license_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_restrictions">
                                        { item.license_restrictions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="license_suspended">
                                        { dataFormatter.booleanFormatter(item.license_suspended) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cpc_number">
                                        { item.cpc_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cpc_issued_at">
                                        { dataFormatter.dateTimeFormatter(item.cpc_issued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cpc_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.cpc_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cpc_center">
                                        { item.cpc_center }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cpc_last_training_at">
                                        { dataFormatter.dateTimeFormatter(item.cpc_last_training_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cpc_next_training_at">
                                        { dataFormatter.dateTimeFormatter(item.cpc_next_training_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cpc_type">
                                        { item.cpc_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adr_number">
                                        { item.adr_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adr_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.adr_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adr_tank">
                                        { dataFormatter.booleanFormatter(item.adr_tank) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adr_packages">
                                        { dataFormatter.booleanFormatter(item.adr_packages) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adr_last_course_at">
                                        { dataFormatter.dateTimeFormatter(item.adr_last_course_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adr_next_course_at">
                                        { dataFormatter.dateTimeFormatter(item.adr_next_course_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adr_restrictions">
                                        { item.adr_restrictions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="medical_cert_number">
                                        { item.medical_cert_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="medical_issued_by">
                                        { item.medical_issued_by }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="medical_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.medical_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="psych_test_number">
                                        { item.psych_test_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="psych_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.psych_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="eye_exam_at">
                                        { dataFormatter.dateTimeFormatter(item.eye_exam_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cardio_exam_at">
                                        { dataFormatter.dateTimeFormatter(item.cardio_exam_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="medical_restrictions">
                                        { item.medical_restrictions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tacho_card_number">
                                        { item.tacho_card_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tacho_country">
                                        { item.tacho_country }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tacho_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.tacho_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tacho_last_download_at">
                                        { dataFormatter.dateTimeFormatter(item.tacho_last_download_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tacho_next_download_at">
                                        { dataFormatter.dateTimeFormatter(item.tacho_next_download_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="violations_count">
                                        { item.violations_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="warnings_count">
                                        { item.warnings_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="driving_ban">
                                        { dataFormatter.booleanFormatter(item.driving_ban) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="driving_ban_until">
                                        { dataFormatter.dateTimeFormatter(item.driving_ban_until) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!driver_profiles?.driver_compliances_driver_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Incidents DriverProfile</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>IncidentType</th>
                                
                                
                                
                                <th>OccurredAt</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Location</th>
                                
                                
                                
                                <th>Paid</th>
                                
                                
                                
                                <th>PaidAt</th>
                                
                                
                                
                                <th>Points</th>
                                
                                
                                
                                <th>Severity</th>
                                
                                
                                
                                <th>ReportedBy</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {driver_profiles.incidents_driver_profile && Array.isArray(driver_profiles.incidents_driver_profile) &&
                              driver_profiles.incidents_driver_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/incidents/incidents-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="type">
                                        { item.type }
                                    </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="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="location">
                                        { item.location }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="paid">
                                        { dataFormatter.booleanFormatter(item.paid) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="paid_at">
                                        { dataFormatter.dateTimeFormatter(item.paid_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="points">
                                        { item.points }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="severity">
                                        { item.severity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reported_by">
                                        { item.reported_by }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!driver_profiles?.incidents_driver_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Documents DriverProfile</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>Scope</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {driver_profiles.documents_driver_profile && Array.isArray(driver_profiles.documents_driver_profile) &&
                              driver_profiles.documents_driver_profile.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/documents/documents-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="type">
                                        { item.type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scope">
                                        { item.scope }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!driver_profiles?.documents_driver_profile?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Driver_profilesView;