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/workspaces/workspacesSlice'
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 WorkspacesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { workspaces } = useAppSelector((state) => state.workspaces)
    
    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 workspaces')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View workspaces')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/workspaces/workspaces-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>LegalName</p>
                    <p>{workspaces?.legal_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Website</p>
                    <p>{workspaces?.website}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Industry</p>
                    <p>{workspaces?.industry}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Country</p>
                    <p>{workspaces?.country}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>BaseCurrency</p>
                    <p>{workspaces?.base_currency}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

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

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Owner</p>
                    
                    
                        <p>{workspaces?.owner?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Workspace_memberships Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>MemberRole</th>
                                
                                
                                
                                <th>InviteStatus</th>
                                
                                
                                
                                <th>InvitedAt</th>
                                
                                
                                
                                <th>AcceptedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.workspace_memberships_workspace && Array.isArray(workspaces.workspace_memberships_workspace) &&
                              workspaces.workspace_memberships_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/workspace_memberships/workspace_memberships-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="member_role">
                                        { item.member_role }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invite_status">
                                        { item.invite_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invited_at">
                                        { dataFormatter.dateTimeFormatter(item.invited_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="accepted_at">
                                        { dataFormatter.dateTimeFormatter(item.accepted_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.workspace_memberships_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Data_connections Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ProviderType</th>
                                
                                
                                
                                <th>ProviderName</th>
                                
                                
                                
                                <th>ConnectionStatus</th>
                                
                                
                                
                                <th>ConnectedAt</th>
                                
                                
                                
                                <th>LastSyncAt</th>
                                
                                
                                
                                <th>ExternalReference</th>
                                
                                
                                
                                <th>ErrorMessage</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.data_connections_workspace && Array.isArray(workspaces.data_connections_workspace) &&
                              workspaces.data_connections_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/data_connections/data_connections-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="provider_type">
                                        { item.provider_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider_name">
                                        { item.provider_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="connection_status">
                                        { item.connection_status }
                                    </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>
                                    
                                    
                                    
                                    <td data-label="external_reference">
                                        { item.external_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_message">
                                        { item.error_message }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.data_connections_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Financial_accounts Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>AccountType</th>
                                
                                
                                
                                <th>AccountName</th>
                                
                                
                                
                                <th>AccountNumberMasked</th>
                                
                                
                                
                                <th>InstitutionName</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>CurrentBalance</th>
                                
                                
                                
                                <th>BalanceAsOf</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.financial_accounts_workspace && Array.isArray(workspaces.financial_accounts_workspace) &&
                              workspaces.financial_accounts_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/financial_accounts/financial_accounts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="account_type">
                                        { item.account_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="account_name">
                                        { item.account_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="account_number_masked">
                                        { item.account_number_masked }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="institution_name">
                                        { item.institution_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="current_balance">
                                        { item.current_balance }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="balance_as_of">
                                        { dataFormatter.dateTimeFormatter(item.balance_as_of) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.financial_accounts_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vendors Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>VendorName</th>
                                
                                
                                
                                <th>TaxID</th>
                                
                                
                                
                                <th>Website</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.vendors_workspace && Array.isArray(workspaces.vendors_workspace) &&
                              workspaces.vendors_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/vendors/vendors-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="vendor_name">
                                        { item.vendor_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_id">
                                        { item.tax_id }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="website">
                                        { item.website }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.vendors_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Customers Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>CustomerName</th>
                                
                                
                                
                                <th>Website</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.customers_workspace && Array.isArray(workspaces.customers_workspace) &&
                              workspaces.customers_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/customers/customers-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="customer_name">
                                        { item.customer_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="website">
                                        { item.website }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.customers_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Transactions Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>PostedAt</th>
                                
                                
                                
                                <th>EffectiveAt</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>MerchantName</th>
                                
                                
                                
                                <th>Direction</th>
                                
                                
                                
                                <th>Category</th>
                                
                                
                                
                                <th>ClassificationStatus</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>ExternalReference</th>
                                
                                
                                
                                <th>IsRecurringCandidate</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.transactions_workspace && Array.isArray(workspaces.transactions_workspace) &&
                              workspaces.transactions_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/transactions/transactions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="posted_at">
                                        { dataFormatter.dateTimeFormatter(item.posted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="effective_at">
                                        { dataFormatter.dateTimeFormatter(item.effective_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="merchant_name">
                                        { item.merchant_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="direction">
                                        { item.direction }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="classification_status">
                                        { item.classification_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="external_reference">
                                        { item.external_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_recurring_candidate">
                                        { dataFormatter.booleanFormatter(item.is_recurring_candidate) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.transactions_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Budgets Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>BudgetName</th>
                                
                                
                                
                                <th>PeriodStart</th>
                                
                                
                                
                                <th>PeriodEnd</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>TotalAmount</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.budgets_workspace && Array.isArray(workspaces.budgets_workspace) &&
                              workspaces.budgets_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/budgets/budgets-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="budget_name">
                                        { item.budget_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_start">
                                        { dataFormatter.dateTimeFormatter(item.period_start) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_end">
                                        { dataFormatter.dateTimeFormatter(item.period_end) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_amount">
                                        { item.total_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.budgets_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Forecasts Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ForecastName</th>
                                
                                
                                
                                <th>Horizon</th>
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>StartingCash</th>
                                
                                
                                
                                <th>ProjectedEndingCash</th>
                                
                                
                                
                                <th>RunwayMonths</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.forecasts_workspace && Array.isArray(workspaces.forecasts_workspace) &&
                              workspaces.forecasts_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/forecasts/forecasts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="forecast_name">
                                        { item.forecast_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="horizon">
                                        { item.horizon }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="start_date">
                                        { dataFormatter.dateTimeFormatter(item.start_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_date">
                                        { dataFormatter.dateTimeFormatter(item.end_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="starting_cash">
                                        { item.starting_cash }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="projected_ending_cash">
                                        { item.projected_ending_cash }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="runway_months">
                                        { item.runway_months }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.forecasts_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Metrics_snapshots Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>AsOfAt</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>CashBalance</th>
                                
                                
                                
                                <th>NetBurnMonthly</th>
                                
                                
                                
                                <th>GrossMarginPercent</th>
                                
                                
                                
                                <th>MRR</th>
                                
                                
                                
                                <th>ARR</th>
                                
                                
                                
                                <th>AccountsReceivable</th>
                                
                                
                                
                                <th>AccountsPayable</th>
                                
                                
                                
                                <th>RunwayMonths</th>
                                
                                
                                
                                <th>QualityGrade</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.metrics_snapshots_workspace && Array.isArray(workspaces.metrics_snapshots_workspace) &&
                              workspaces.metrics_snapshots_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/metrics_snapshots/metrics_snapshots-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="as_of_at">
                                        { dataFormatter.dateTimeFormatter(item.as_of_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cash_balance">
                                        { item.cash_balance }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="net_burn_monthly">
                                        { item.net_burn_monthly }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gross_margin_percent">
                                        { item.gross_margin_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="mrr">
                                        { item.mrr }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="arr">
                                        { item.arr }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="accounts_receivable">
                                        { item.accounts_receivable }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="accounts_payable">
                                        { item.accounts_payable }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="runway_months">
                                        { item.runway_months }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quality_grade">
                                        { item.quality_grade }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.metrics_snapshots_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Anomalies Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>AnomalyType</th>
                                
                                
                                
                                <th>Severity</th>
                                
                                
                                
                                <th>AnomalyScore</th>
                                
                                
                                
                                <th>Summary</th>
                                
                                
                                
                                <th>Explanation</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>DetectedAt</th>
                                
                                
                                
                                <th>ResolvedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.anomalies_workspace && Array.isArray(workspaces.anomalies_workspace) &&
                              workspaces.anomalies_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/anomalies/anomalies-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="anomaly_type">
                                        { item.anomaly_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="severity">
                                        { item.severity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="anomaly_score">
                                        { item.anomaly_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="summary">
                                        { item.summary }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="explanation">
                                        { item.explanation }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="detected_at">
                                        { dataFormatter.dateTimeFormatter(item.detected_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="resolved_at">
                                        { dataFormatter.dateTimeFormatter(item.resolved_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.anomalies_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Alerts Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>AlertType</th>
                                
                                
                                
                                <th>Severity</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>Message</th>
                                
                                
                                
                                <th>TriggeredAt</th>
                                
                                
                                
                                <th>AcknowledgedAt</th>
                                
                                
                                
                                <th>ResolvedAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.alerts_workspace && Array.isArray(workspaces.alerts_workspace) &&
                              workspaces.alerts_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/alerts/alerts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="alert_type">
                                        { item.alert_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="severity">
                                        { item.severity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title_text">
                                        { item.title_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="message">
                                        { item.message }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="triggered_at">
                                        { dataFormatter.dateTimeFormatter(item.triggered_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="acknowledged_at">
                                        { dataFormatter.dateTimeFormatter(item.acknowledged_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="resolved_at">
                                        { dataFormatter.dateTimeFormatter(item.resolved_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.alerts_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Recommendations Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>RecommendationType</th>
                                
                                
                                
                                <th>Priority</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>Rationale</th>
                                
                                
                                
                                <th>ActionSteps</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>CreatedOn</th>
                                
                                
                                
                                <th>DueOn</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.recommendations_workspace && Array.isArray(workspaces.recommendations_workspace) &&
                              workspaces.recommendations_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/recommendations/recommendations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="recommendation_type">
                                        { item.recommendation_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="priority">
                                        { item.priority }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title_text">
                                        { item.title_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rationale">
                                        { item.rationale }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="action_steps">
                                        { item.action_steps }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_on">
                                        { dataFormatter.dateTimeFormatter(item.created_on) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_on">
                                        { dataFormatter.dateTimeFormatter(item.due_on) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.recommendations_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chat_threads Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>ThreadTitle</th>
                                
                                
                                
                                <th>ThreadType</th>
                                
                                
                                
                                <th>LastMessageAt</th>
                                
                                
                                
                                <th>IsPinned</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.chat_threads_workspace && Array.isArray(workspaces.chat_threads_workspace) &&
                              workspaces.chat_threads_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/chat_threads/chat_threads-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="thread_title">
                                        { item.thread_title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="thread_type">
                                        { item.thread_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_message_at">
                                        { dataFormatter.dateTimeFormatter(item.last_message_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_pinned">
                                        { dataFormatter.booleanFormatter(item.is_pinned) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.chat_threads_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Files_library Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>FileType</th>
                                
                                
                                
                                <th>FileName</th>
                                
                                
                                
                                
                                
                                <th>UploadedAt</th>
                                
                                
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.files_library_workspace && Array.isArray(workspaces.files_library_workspace) &&
                              workspaces.files_library_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/files_library/files_library-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="file_type">
                                        { item.file_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="file_name">
                                        { item.file_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="uploaded_at">
                                        { dataFormatter.dateTimeFormatter(item.uploaded_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.files_library_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Sync_jobs Workspace</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>JobType</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>FinishedAt</th>
                                
                                
                                
                                <th>RecordsProcessed</th>
                                
                                
                                
                                <th>ErrorMessage</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {workspaces.sync_jobs_workspace && Array.isArray(workspaces.sync_jobs_workspace) &&
                              workspaces.sync_jobs_workspace.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/sync_jobs/sync_jobs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="job_type">
                                        { item.job_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </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="records_processed">
                                        { item.records_processed }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_message">
                                        { item.error_message }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!workspaces?.sync_jobs_workspace?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                

                <BaseDivider />

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

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

export default WorkspacesView;