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/tenants/tenantsSlice';
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 TenantsView = () => {
  const router = useRouter();
  const dispatch = useAppDispatch();
  const { tenants } = useAppSelector((state) => state.tenants);

  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 tenants')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton
          icon={mdiChartTimelineVariant}
          title={removeLastCharacter('View tenants')}
          main
        >
          <BaseButton
            color='info'
            label='Edit'
            href={`/tenants/tenants-edit/?id=${id}`}
          />
        </SectionTitleLineWithButton>
        <CardBox>
          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Name</p>
            <p>{tenants?.name}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Subdomain</p>
            <p>{tenants?.subdomain}</p>
          </div>

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

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Plan</p>

            <p>{tenants?.plan?.name ?? 'No data'}</p>
          </div>

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

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>BillingEmail</p>
            <p>{tenants?.billing_email}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>BillingPhone</p>
            <p>{tenants?.billing_phone}</p>
          </div>

          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>agences</p>

            <p>{tenants?.agences?.name ?? 'No data'}</p>
          </div>

          <>
            <p className={'block font-bold mb-2'}>Claims Tenant</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>Description</th>

                      <th>Status</th>

                      <th>Attachments</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.claims_tenant &&
                      Array.isArray(tenants.claims_tenant) &&
                      tenants.claims_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/claims/claims-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='category'>{item.category}</td>

                          <td data-label='description'>{item.description}</td>

                          <td data-label='status'>{item.status}</td>

                          <td data-label='attachments'>{item.attachments}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.claims_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Clients Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FirstName</th>

                      <th>LastName</th>

                      <th>BirthDate</th>

                      <th>Phone</th>

                      <th>Address</th>

                      <th>IDType</th>

                      <th>IDNumber</th>

                      <th>IDIssueDate</th>

                      <th>LicenseNumber</th>

                      <th>LicenseIssueDate</th>

                      <th>IDCopyURL</th>

                      <th>LicenseCopyURL</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.clients_tenant &&
                      Array.isArray(tenants.clients_tenant) &&
                      tenants.clients_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/clients/clients-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='first_name'>{item.first_name}</td>

                          <td data-label='last_name'>{item.last_name}</td>

                          <td data-label='birth_date'>
                            {dataFormatter.dateTimeFormatter(item.birth_date)}
                          </td>

                          <td data-label='phone'>{item.phone}</td>

                          <td data-label='address'>{item.address}</td>

                          <td data-label='id_type'>{item.id_type}</td>

                          <td data-label='id_number'>{item.id_number}</td>

                          <td data-label='id_issue_date'>
                            {dataFormatter.dateTimeFormatter(
                              item.id_issue_date,
                            )}
                          </td>

                          <td data-label='license_number'>
                            {item.license_number}
                          </td>

                          <td data-label='license_issue_date'>
                            {dataFormatter.dateTimeFormatter(
                              item.license_issue_date,
                            )}
                          </td>

                          <td data-label='id_copy_url'>{item.id_copy_url}</td>

                          <td data-label='license_copy_url'>
                            {item.license_copy_url}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.clients_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Company_profiles Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>LegalName</th>

                      <th>Address</th>

                      <th>Phone</th>

                      <th>Email</th>

                      <th>Website</th>

                      <th>RC</th>

                      <th>ICE</th>

                      <th>Patente</th>

                      <th>LogoURL</th>

                      <th>PDFFooter</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.company_profiles_tenant &&
                      Array.isArray(tenants.company_profiles_tenant) &&
                      tenants.company_profiles_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/company_profiles/company_profiles-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='legal_name'>{item.legal_name}</td>

                          <td data-label='address'>{item.address}</td>

                          <td data-label='phone'>{item.phone}</td>

                          <td data-label='email'>{item.email}</td>

                          <td data-label='website'>{item.website}</td>

                          <td data-label='rc'>{item.rc}</td>

                          <td data-label='ice'>{item.ice}</td>

                          <td data-label='patente'>{item.patente}</td>

                          <td data-label='logo_url'>{item.logo_url}</td>

                          <td data-label='pdf_footer'>{item.pdf_footer}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.company_profiles_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Drivers Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FullName</th>

                      <th>LicenseNumber</th>

                      <th>LicenseIssueDate</th>

                      <th>IDCopyURL</th>

                      <th>LicenseCopyURL</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.drivers_tenant &&
                      Array.isArray(tenants.drivers_tenant) &&
                      tenants.drivers_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/drivers/drivers-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='full_name'>{item.full_name}</td>

                          <td data-label='license_number'>
                            {item.license_number}
                          </td>

                          <td data-label='license_issue_date'>
                            {dataFormatter.dateTimeFormatter(
                              item.license_issue_date,
                            )}
                          </td>

                          <td data-label='id_copy_url'>{item.id_copy_url}</td>

                          <td data-label='license_copy_url'>
                            {item.license_copy_url}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.drivers_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Expenses Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Type</th>

                      <th>Category</th>

                      <th>Amount</th>

                      <th>Date</th>

                      <th>Note</th>

                      <th>AttachmentURL</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.expenses_tenant &&
                      Array.isArray(tenants.expenses_tenant) &&
                      tenants.expenses_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/expenses/expenses-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='type'>{item.type}</td>

                          <td data-label='category'>{item.category}</td>

                          <td data-label='amount'>{item.amount}</td>

                          <td data-label='date'>
                            {dataFormatter.dateTimeFormatter(item.date)}
                          </td>

                          <td data-label='note'>{item.note}</td>

                          <td data-label='attachment_url'>
                            {item.attachment_url}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.expenses_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Guarantees Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Method</th>

                      <th>Amount</th>

                      <th>Status</th>

                      <th>ProofURL</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.guarantees_tenant &&
                      Array.isArray(tenants.guarantees_tenant) &&
                      tenants.guarantees_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/guarantees/guarantees-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='method'>{item.method}</td>

                          <td data-label='amount'>{item.amount}</td>

                          <td data-label='status'>{item.status}</td>

                          <td data-label='proof_url'>{item.proof_url}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.guarantees_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Infractions Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>ReferenceNumber</th>

                      <th>Date</th>

                      <th>Location</th>

                      <th>Amount</th>

                      <th>Status</th>

                      <th>ProofURL</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.infractions_tenant &&
                      Array.isArray(tenants.infractions_tenant) &&
                      tenants.infractions_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/infractions/infractions-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='ref_no'>{item.ref_no}</td>

                          <td data-label='date'>
                            {dataFormatter.dateTimeFormatter(item.date)}
                          </td>

                          <td data-label='location'>{item.location}</td>

                          <td data-label='amount'>{item.amount}</td>

                          <td data-label='status'>{item.status}</td>

                          <td data-label='proof_url'>{item.proof_url}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.infractions_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Invoices_saas Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>InvoiceNumber</th>

                      <th>AmountMAD</th>

                      <th>Status</th>

                      <th>IssuedAt</th>

                      <th>PDFURL</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.invoices_saas_tenant &&
                      Array.isArray(tenants.invoices_saas_tenant) &&
                      tenants.invoices_saas_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/invoices_saas/invoices_saas-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='invoice_number'>
                            {item.invoice_number}
                          </td>

                          <td data-label='amount_mad'>{item.amount_mad}</td>

                          <td data-label='status'>{item.status}</td>

                          <td data-label='issued_at'>
                            {dataFormatter.dateTimeFormatter(item.issued_at)}
                          </td>

                          <td data-label='pdf_url'>{item.pdf_url}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.invoices_saas_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Maintenance Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Type</th>

                      <th>ScheduledAt</th>

                      <th>Odometer</th>

                      <th>Cost</th>

                      <th>Notes</th>

                      <th>Attachments</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.maintenance_tenant &&
                      Array.isArray(tenants.maintenance_tenant) &&
                      tenants.maintenance_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/maintenance/maintenance-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='type'>{item.type}</td>

                          <td data-label='scheduled_at'>
                            {dataFormatter.dateTimeFormatter(item.scheduled_at)}
                          </td>

                          <td data-label='odometer'>{item.odometer}</td>

                          <td data-label='cost'>{item.cost}</td>

                          <td data-label='notes'>{item.notes}</td>

                          <td data-label='attachments'>{item.attachments}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.maintenance_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Payments Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Method</th>

                      <th>Amount</th>

                      <th>PaidAt</th>

                      <th>ReceiptReference</th>

                      <th>AttachmentURL</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.payments_tenant &&
                      Array.isArray(tenants.payments_tenant) &&
                      tenants.payments_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/payments/payments-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='method'>{item.method}</td>

                          <td data-label='amount'>{item.amount}</td>

                          <td data-label='paid_at'>
                            {dataFormatter.dateTimeFormatter(item.paid_at)}
                          </td>

                          <td data-label='receipt_ref'>{item.receipt_ref}</td>

                          <td data-label='attachment_url'>
                            {item.attachment_url}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.payments_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Reservations Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Reference</th>

                      <th>StatusManual</th>

                      <th>StatusComputed</th>

                      <th>StartAt</th>

                      <th>EndAt</th>

                      <th>PickupAddress</th>

                      <th>ReturnAddress</th>

                      <th>Options</th>

                      <th>Days</th>

                      <th>PricePerDay</th>

                      <th>TotalPrice</th>

                      <th>PaidAmount</th>

                      <th>BalanceAmount</th>

                      <th>GuaranteeMethod</th>

                      <th>GuaranteeAmount</th>

                      <th>GuaranteeStatus</th>

                      <th>DepartureValidatedAt</th>

                      <th>ReturnValidatedAt</th>

                      <th>Notes</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.reservations_tenant &&
                      Array.isArray(tenants.reservations_tenant) &&
                      tenants.reservations_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/reservations/reservations-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='ref'>{item.ref}</td>

                          <td data-label='status_manual'>
                            {item.status_manual}
                          </td>

                          <td data-label='status_computed'>
                            {item.status_computed}
                          </td>

                          <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='pickup_address'>
                            {item.pickup_address}
                          </td>

                          <td data-label='return_address'>
                            {item.return_address}
                          </td>

                          <td data-label='options'>{item.options}</td>

                          <td data-label='days'>{item.days}</td>

                          <td data-label='price_per_day'>
                            {item.price_per_day}
                          </td>

                          <td data-label='total_price'>{item.total_price}</td>

                          <td data-label='paid_amount'>{item.paid_amount}</td>

                          <td data-label='balance_amount'>
                            {item.balance_amount}
                          </td>

                          <td data-label='guarantee_method'>
                            {item.guarantee_method}
                          </td>

                          <td data-label='guarantee_amount'>
                            {item.guarantee_amount}
                          </td>

                          <td data-label='guarantee_status'>
                            {item.guarantee_status}
                          </td>

                          <td data-label='departure_validated_at'>
                            {dataFormatter.dateTimeFormatter(
                              item.departure_validated_at,
                            )}
                          </td>

                          <td data-label='return_validated_at'>
                            {dataFormatter.dateTimeFormatter(
                              item.return_validated_at,
                            )}
                          </td>

                          <td data-label='notes'>{item.notes}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.reservations_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Subscriptions Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Status</th>

                      <th>CurrentPeriodStart</th>

                      <th>CurrentPeriodEnd</th>

                      <th>PaymentProvider</th>

                      <th>ProviderCustomerID</th>

                      <th>ProviderSubscriptionID</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.subscriptions_tenant &&
                      Array.isArray(tenants.subscriptions_tenant) &&
                      tenants.subscriptions_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/subscriptions/subscriptions-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='status'>{item.status}</td>

                          <td data-label='current_period_start'>
                            {dataFormatter.dateTimeFormatter(
                              item.current_period_start,
                            )}
                          </td>

                          <td data-label='current_period_end'>
                            {dataFormatter.dateTimeFormatter(
                              item.current_period_end,
                            )}
                          </td>

                          <td data-label='payment_provider'>
                            {item.payment_provider}
                          </td>

                          <td data-label='provider_customer_id'>
                            {item.provider_customer_id}
                          </td>

                          <td data-label='provider_subscription_id'>
                            {item.provider_subscription_id}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.subscriptions_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Vehicle_conditions Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Before</th>

                      <th>After</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.vehicle_conditions_tenant &&
                      Array.isArray(tenants.vehicle_conditions_tenant) &&
                      tenants.vehicle_conditions_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/vehicle_conditions/vehicle_conditions-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='before'>{item.before}</td>

                          <td data-label='after'>{item.after}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.vehicle_conditions_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Vehicles Tenant</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>PlateNumber</th>

                      <th>Brand</th>

                      <th>Model</th>

                      <th>Year</th>

                      <th>Color</th>

                      <th>Category</th>

                      <th>FuelType</th>

                      <th>Transmission</th>

                      <th>Mileage</th>

                      <th>DailyPrice</th>

                      <th>Status</th>

                      <th>InsuranceExpiry</th>

                      <th>TechVisitExpiry</th>

                      <th>Photos</th>
                    </tr>
                  </thead>
                  <tbody>
                    {tenants.vehicles_tenant &&
                      Array.isArray(tenants.vehicles_tenant) &&
                      tenants.vehicles_tenant.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/vehicles/vehicles-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='plate_number'>{item.plate_number}</td>

                          <td data-label='brand'>{item.brand}</td>

                          <td data-label='model'>{item.model}</td>

                          <td data-label='year'>{item.year}</td>

                          <td data-label='color'>{item.color}</td>

                          <td data-label='category'>{item.category}</td>

                          <td data-label='fuel_type'>{item.fuel_type}</td>

                          <td data-label='transmission'>{item.transmission}</td>

                          <td data-label='mileage'>{item.mileage}</td>

                          <td data-label='daily_price'>{item.daily_price}</td>

                          <td data-label='status'>{item.status}</td>

                          <td data-label='insurance_expiry'>
                            {dataFormatter.dateTimeFormatter(
                              item.insurance_expiry,
                            )}
                          </td>

                          <td data-label='tech_visit_expiry'>
                            {dataFormatter.dateTimeFormatter(
                              item.tech_visit_expiry,
                            )}
                          </td>

                          <td data-label='photos'>{item.photos}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!tenants?.vehicles_tenant?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <BaseDivider />

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

TenantsView.getLayout = function getLayout(page: ReactElement) {
  return (
    <LayoutAuthenticated permission={'READ_TENANTS'}>
      {page}
    </LayoutAuthenticated>
  );
};

export default TenantsView;
