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'}>TenantName</p>
                    <p>{tenants?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Status</p>
                    <p>{tenants?.status ?? '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'}>Timezone</p>
                    <p>{tenants?.timezone}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <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'}>organizations</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{tenants?.organizations?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Pipelines Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PipelineName</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>IsDefault</th>
                                
                                
                                
                                <th>SortOrder</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.pipelines_tenant && Array.isArray(tenants.pipelines_tenant) &&
                              tenants.pipelines_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/pipelines/pipelines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_default">
                                        { dataFormatter.booleanFormatter(item.is_default) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sort_order">
                                        { item.sort_order }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.pipelines_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Companies Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>CompanyName</th>
                                
                                
                                
                                <th>Domain</th>
                                
                                
                                
                                <th>Phone</th>
                                
                                
                                
                                <th>Website</th>
                                
                                
                                
                                <th>Industry</th>
                                
                                
                                
                                <th>EmployeeCount</th>
                                
                                
                                
                                <th>AnnualRevenue</th>
                                
                                
                                
                                <th>AddressLine1</th>
                                
                                
                                
                                <th>AddressLine2</th>
                                
                                
                                
                                <th>City</th>
                                
                                
                                
                                <th>State</th>
                                
                                
                                
                                <th>PostalCode</th>
                                
                                
                                
                                <th>Country</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.companies_tenant && Array.isArray(tenants.companies_tenant) &&
                              tenants.companies_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/companies/companies-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="domain">
                                        { item.domain }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="website">
                                        { item.website }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="industry">
                                        { item.industry }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="employee_count">
                                        { item.employee_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="annual_revenue">
                                        { item.annual_revenue }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_line1">
                                        { item.address_line1 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_line2">
                                        { item.address_line2 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="city">
                                        { item.city }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="state">
                                        { item.state }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="postal_code">
                                        { item.postal_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="country">
                                        { item.country }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.companies_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Contacts 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>Email</th>
                                
                                
                                
                                <th>Phone</th>
                                
                                
                                
                                <th>JobTitle</th>
                                
                                
                                
                                <th>LifecycleStage</th>
                                
                                
                                
                                
                                
                                <th>LinkedInURL</th>
                                
                                
                                
                                
                                
                                <th>DoNotContact</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.contacts_tenant && Array.isArray(tenants.contacts_tenant) &&
                              tenants.contacts_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/contacts/contacts-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="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="job_title">
                                        { item.job_title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lifecycle_stage">
                                        { item.lifecycle_stage }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="linkedin_url">
                                        { item.linkedin_url }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="do_not_contact">
                                        { dataFormatter.booleanFormatter(item.do_not_contact) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.contacts_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Leads 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>Email</th>
                                
                                
                                
                                <th>Phone</th>
                                
                                
                                
                                <th>CompanyName</th>
                                
                                
                                
                                <th>JobTitle</th>
                                
                                
                                
                                <th>LeadSource</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Score</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.leads_tenant && Array.isArray(tenants.leads_tenant) &&
                              tenants.leads_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/leads/leads-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="full_name">
                                        { item.full_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="company_name">
                                        { item.company_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="job_title">
                                        { item.job_title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lead_source">
                                        { item.lead_source }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="score">
                                        { item.score }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.leads_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Deals Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>DealName</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>ExpectedCloseAt</th>
                                
                                
                                
                                <th>ClosedAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LossReason</th>
                                
                                
                                
                                
                                
                                <th>Priority</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.deals_tenant && Array.isArray(tenants.deals_tenant) &&
                              tenants.deals_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/deals/deals-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expected_close_at">
                                        { dataFormatter.dateTimeFormatter(item.expected_close_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="closed_at">
                                        { dataFormatter.dateTimeFormatter(item.closed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="loss_reason">
                                        { item.loss_reason }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="priority">
                                        { item.priority }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.deals_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Activities Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>ActivityType</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Subject</th>
                                
                                
                                
                                
                                
                                <th>OccurredAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.activities_tenant && Array.isArray(tenants.activities_tenant) &&
                              tenants.activities_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/activities/activities-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="activity_type">
                                        { item.activity_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="subject">
                                        { item.subject }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="occurred_at">
                                        { dataFormatter.dateTimeFormatter(item.occurred_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.activities_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Tasks Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Priority</th>
                                
                                
                                
                                <th>DueAt</th>
                                
                                
                                
                                <th>CompletedAt</th>
                                
                                
                                
                                <th>IsOverdue</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.tasks_tenant && Array.isArray(tenants.tasks_tenant) &&
                              tenants.tasks_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/tasks/tasks-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="priority">
                                        { item.priority }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_at">
                                        { dataFormatter.dateTimeFormatter(item.due_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="completed_at">
                                        { dataFormatter.dateTimeFormatter(item.completed_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_overdue">
                                        { dataFormatter.booleanFormatter(item.is_overdue) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.tasks_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Reminders Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Message</th>
                                
                                
                                
                                <th>RemindAt</th>
                                
                                
                                
                                <th>Channel</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.reminders_tenant && Array.isArray(tenants.reminders_tenant) &&
                              tenants.reminders_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/reminders/reminders-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="message">
                                        { item.message }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="remind_at">
                                        { dataFormatter.dateTimeFormatter(item.remind_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="channel">
                                        { item.channel }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.reminders_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Email_templates Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>TemplateName</th>
                                
                                
                                
                                <th>Subject</th>
                                
                                
                                
                                
                                
                                <th>TextBody</th>
                                
                                
                                
                                <th>TemplateType</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.email_templates_tenant && Array.isArray(tenants.email_templates_tenant) &&
                              tenants.email_templates_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/email_templates/email_templates-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="subject">
                                        { item.subject }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="text_body">
                                        { item.text_body }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="template_type">
                                        { item.template_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.email_templates_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Email_notifications Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ToAddress</th>
                                
                                
                                
                                <th>Subject</th>
                                
                                
                                
                                <th>BodyPreview</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>QueuedAt</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>FailureReason</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.email_notifications_tenant && Array.isArray(tenants.email_notifications_tenant) &&
                              tenants.email_notifications_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/email_notifications/email_notifications-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="to_address">
                                        { item.to_address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="subject">
                                        { item.subject }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="body_preview">
                                        { item.body_preview }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="queued_at">
                                        { dataFormatter.dateTimeFormatter(item.queued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="failure_reason">
                                        { item.failure_reason }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.email_notifications_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Imports Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>EntityType</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                <th>MappingJSON</th>
                                
                                
                                
                                <th>TotalRows</th>
                                
                                
                                
                                <th>ProcessedRows</th>
                                
                                
                                
                                <th>SuccessRows</th>
                                
                                
                                
                                <th>ErrorRows</th>
                                
                                
                                
                                <th>ErrorReport</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>FinishedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.imports_tenant && Array.isArray(tenants.imports_tenant) &&
                              tenants.imports_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/imports/imports-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="entity_type">
                                        { item.entity_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="mapping_json">
                                        { item.mapping_json }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_rows">
                                        { item.total_rows }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="processed_rows">
                                        { item.processed_rows }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="success_rows">
                                        { item.success_rows }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_rows">
                                        { item.error_rows }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_report">
                                        { item.error_report }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="finished_at">
                                        { dataFormatter.dateTimeFormatter(item.finished_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.imports_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Exports Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>EntityType</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>FiltersJSON</th>
                                
                                
                                
                                
                                
                                <th>TotalRows</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>FinishedAt</th>
                                
                                
                                
                                <th>FailureReason</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.exports_tenant && Array.isArray(tenants.exports_tenant) &&
                              tenants.exports_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/exports/exports-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="entity_type">
                                        { item.entity_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="filters_json">
                                        { item.filters_json }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="total_rows">
                                        { item.total_rows }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="finished_at">
                                        { dataFormatter.dateTimeFormatter(item.finished_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="failure_reason">
                                        { item.failure_reason }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.exports_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Api_clients Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ClientName</th>
                                
                                
                                
                                <th>ClientKey</th>
                                
                                
                                
                                <th>ClientSecretHash</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LastUsedAt</th>
                                
                                
                                
                                <th>AllowedIPs</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.api_clients_tenant && Array.isArray(tenants.api_clients_tenant) &&
                              tenants.api_clients_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/api_clients/api_clients-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="client_key">
                                        { item.client_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="client_secret_hash">
                                        { item.client_secret_hash }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_used_at">
                                        { dataFormatter.dateTimeFormatter(item.last_used_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="allowed_ips">
                                        { item.allowed_ips }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.api_clients_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Api_tokens Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>TokenHash</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LastUsedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.api_tokens_tenant && Array.isArray(tenants.api_tokens_tenant) &&
                              tenants.api_tokens_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/api_tokens/api_tokens-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="token_hash">
                                        { item.token_hash }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_used_at">
                                        { dataFormatter.dateTimeFormatter(item.last_used_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.api_tokens_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Webhooks Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>WebhookName</th>
                                
                                
                                
                                <th>TargetURL</th>
                                
                                
                                
                                <th>Secret</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>EventTypes</th>
                                
                                
                                
                                <th>TimeoutSeconds</th>
                                
                                
                                
                                <th>MaxRetries</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.webhooks_tenant && Array.isArray(tenants.webhooks_tenant) &&
                              tenants.webhooks_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/webhooks/webhooks-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="target_url">
                                        { item.target_url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="secret">
                                        { item.secret }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="event_types">
                                        { item.event_types }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="timeout_seconds">
                                        { item.timeout_seconds }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_retries">
                                        { item.max_retries }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.webhooks_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Webhook_deliveries Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>EventType</th>
                                
                                
                                
                                <th>PayloadJSON</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>AttemptCount</th>
                                
                                
                                
                                <th>HTTPStatus</th>
                                
                                
                                
                                <th>ResponseBody</th>
                                
                                
                                
                                <th>NextAttemptAt</th>
                                
                                
                                
                                <th>DeliveredAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.webhook_deliveries_tenant && Array.isArray(tenants.webhook_deliveries_tenant) &&
                              tenants.webhook_deliveries_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/webhook_deliveries/webhook_deliveries-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="event_type">
                                        { item.event_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="payload_json">
                                        { item.payload_json }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="attempt_count">
                                        { item.attempt_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="http_status">
                                        { item.http_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="response_body">
                                        { item.response_body }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="next_attempt_at">
                                        { dataFormatter.dateTimeFormatter(item.next_attempt_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivered_at">
                                        { dataFormatter.dateTimeFormatter(item.delivered_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.webhook_deliveries_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Integrations Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Provider</th>
                                
                                
                                
                                <th>IntegrationName</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>ConfigJSON</th>
                                
                                
                                
                                <th>ConnectedAt</th>
                                
                                
                                
                                <th>LastSyncAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.integrations_tenant && Array.isArray(tenants.integrations_tenant) &&
                              tenants.integrations_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/integrations/integrations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="provider">
                                        { item.provider }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="config_json">
                                        { item.config_json }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="connected_at">
                                        { dataFormatter.dateTimeFormatter(item.connected_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_sync_at">
                                        { dataFormatter.dateTimeFormatter(item.last_sync_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.integrations_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Calendar_accounts Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ProviderAccountEmail</th>
                                
                                
                                
                                <th>AccessTokenEncrypted</th>
                                
                                
                                
                                <th>RefreshTokenEncrypted</th>
                                
                                
                                
                                <th>TokenExpiresAt</th>
                                
                                
                                
                                <th>SyncStatus</th>
                                
                                
                                
                                <th>LastSyncedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.calendar_accounts_tenant && Array.isArray(tenants.calendar_accounts_tenant) &&
                              tenants.calendar_accounts_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/calendar_accounts/calendar_accounts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="provider_account_email">
                                        { item.provider_account_email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="access_token_encrypted">
                                        { item.access_token_encrypted }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="refresh_token_encrypted">
                                        { item.refresh_token_encrypted }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="token_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.token_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sync_status">
                                        { item.sync_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_synced_at">
                                        { dataFormatter.dateTimeFormatter(item.last_synced_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.calendar_accounts_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Calendar_events Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ProviderEventID</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                
                                
                                <th>StartAt</th>
                                
                                
                                
                                <th>EndAt</th>
                                
                                
                                
                                <th>Location</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LastSyncedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.calendar_events_tenant && Array.isArray(tenants.calendar_events_tenant) &&
                              tenants.calendar_events_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/calendar_events/calendar_events-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="provider_event_id">
                                        { item.provider_event_id }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </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="location">
                                        { item.location }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_synced_at">
                                        { dataFormatter.dateTimeFormatter(item.last_synced_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.calendar_events_tenant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Dashboard_widgets Tenant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>WidgetName</th>
                                
                                
                                
                                <th>WidgetType</th>
                                
                                
                                
                                <th>ConfigJSON</th>
                                
                                
                                
                                <th>PositionX</th>
                                
                                
                                
                                <th>PositionY</th>
                                
                                
                                
                                <th>Width</th>
                                
                                
                                
                                <th>Height</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {tenants.dashboard_widgets_tenant && Array.isArray(tenants.dashboard_widgets_tenant) &&
                              tenants.dashboard_widgets_tenant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/dashboard_widgets/dashboard_widgets-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="widget_type">
                                        { item.widget_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="config_json">
                                        { item.config_json }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="position_x">
                                        { item.position_x }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="position_y">
                                        { item.position_y }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="width">
                                        { item.width }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="height">
                                        { item.height }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!tenants?.dashboard_widgets_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;