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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

                
                <>
                    <p className={'block font-bold mb-2'}>Users Organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>First Name</th>
                                
                                
                                
                                <th>Last Name</th>
                                
                                
                                
                                <th>Phone Number</th>
                                
                                
                                
                                <th>E-Mail</th>
                                
                                
                                
                                <th>Disabled</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.users_organizations && Array.isArray(organizations.users_organizations) &&
                              organizations.users_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/users/users-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="firstName">
                                        { item.firstName }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="lastName">
                                        { item.lastName }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phoneNumber">
                                        { item.phoneNumber }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="disabled">
                                        { dataFormatter.booleanFormatter(item.disabled) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.users_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Workspaces organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>WorkspaceName</th>
                                
                                
                                
                                <th>LegalName</th>
                                
                                
                                
                                <th>Website</th>
                                
                                
                                
                                <th>Industry</th>
                                
                                
                                
                                <th>Country</th>
                                
                                
                                
                                <th>BaseCurrency</th>
                                
                                
                                
                                <th>OnboardedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.workspaces_organizations && Array.isArray(organizations.workspaces_organizations) &&
                              organizations.workspaces_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/workspaces/workspaces-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="legal_name">
                                        { item.legal_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="website">
                                        { item.website }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="industry">
                                        { item.industry }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="country">
                                        { item.country }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_currency">
                                        { item.base_currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="onboarded_at">
                                        { dataFormatter.dateTimeFormatter(item.onboarded_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.workspaces_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Workspace_memberships organizations</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>
                            {organizations.workspace_memberships_organizations && Array.isArray(organizations.workspace_memberships_organizations) &&
                              organizations.workspace_memberships_organizations.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>
                        {!organizations?.workspace_memberships_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Data_connections organizations</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>
                            {organizations.data_connections_organizations && Array.isArray(organizations.data_connections_organizations) &&
                              organizations.data_connections_organizations.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>
                        {!organizations?.data_connections_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Financial_accounts organizations</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>
                            {organizations.financial_accounts_organizations && Array.isArray(organizations.financial_accounts_organizations) &&
                              organizations.financial_accounts_organizations.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>
                        {!organizations?.financial_accounts_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Vendors organizations</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>
                            {organizations.vendors_organizations && Array.isArray(organizations.vendors_organizations) &&
                              organizations.vendors_organizations.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>
                        {!organizations?.vendors_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Customers organizations</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>
                            {organizations.customers_organizations && Array.isArray(organizations.customers_organizations) &&
                              organizations.customers_organizations.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>
                        {!organizations?.customers_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Transactions organizations</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>
                            {organizations.transactions_organizations && Array.isArray(organizations.transactions_organizations) &&
                              organizations.transactions_organizations.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>
                        {!organizations?.transactions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Budgets organizations</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>
                            {organizations.budgets_organizations && Array.isArray(organizations.budgets_organizations) &&
                              organizations.budgets_organizations.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>
                        {!organizations?.budgets_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Budget_lines organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Category</th>
                                
                                
                                
                                <th>PlannedAmount</th>
                                
                                
                                
                                <th>ActualAmount</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.budget_lines_organizations && Array.isArray(organizations.budget_lines_organizations) &&
                              organizations.budget_lines_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/budget_lines/budget_lines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="planned_amount">
                                        { item.planned_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="actual_amount">
                                        { item.actual_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.budget_lines_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Forecasts organizations</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>
                            {organizations.forecasts_organizations && Array.isArray(organizations.forecasts_organizations) &&
                              organizations.forecasts_organizations.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>
                        {!organizations?.forecasts_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Forecast_scenarios organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ScenarioName</th>
                                
                                
                                
                                <th>ScenarioType</th>
                                
                                
                                
                                <th>RevenueMultiplier</th>
                                
                                
                                
                                <th>ExpenseMultiplier</th>
                                
                                
                                
                                <th>CashBufferTarget</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                                
                                <th>Assumptions</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.forecast_scenarios_organizations && Array.isArray(organizations.forecast_scenarios_organizations) &&
                              organizations.forecast_scenarios_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/forecast_scenarios/forecast_scenarios-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="scenario_name">
                                        { item.scenario_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scenario_type">
                                        { item.scenario_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="revenue_multiplier">
                                        { item.revenue_multiplier }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expense_multiplier">
                                        { item.expense_multiplier }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cash_buffer_target">
                                        { item.cash_buffer_target }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="assumptions">
                                        { item.assumptions }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.forecast_scenarios_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Metrics_snapshots organizations</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>
                            {organizations.metrics_snapshots_organizations && Array.isArray(organizations.metrics_snapshots_organizations) &&
                              organizations.metrics_snapshots_organizations.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>
                        {!organizations?.metrics_snapshots_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Anomalies organizations</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>
                            {organizations.anomalies_organizations && Array.isArray(organizations.anomalies_organizations) &&
                              organizations.anomalies_organizations.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>
                        {!organizations?.anomalies_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Alerts organizations</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>
                            {organizations.alerts_organizations && Array.isArray(organizations.alerts_organizations) &&
                              organizations.alerts_organizations.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>
                        {!organizations?.alerts_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Recommendations organizations</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>
                            {organizations.recommendations_organizations && Array.isArray(organizations.recommendations_organizations) &&
                              organizations.recommendations_organizations.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>
                        {!organizations?.recommendations_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chat_threads organizations</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>
                            {organizations.chat_threads_organizations && Array.isArray(organizations.chat_threads_organizations) &&
                              organizations.chat_threads_organizations.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>
                        {!organizations?.chat_threads_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chat_messages organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>AuthorType</th>
                                
                                
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>MessageKind</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.chat_messages_organizations && Array.isArray(organizations.chat_messages_organizations) &&
                              organizations.chat_messages_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/chat_messages/chat_messages-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="author_type">
                                        { item.author_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="message_kind">
                                        { item.message_kind }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.chat_messages_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Message_citations organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>SourceType</th>
                                
                                
                                
                                <th>SourceLabel</th>
                                
                                
                                
                                <th>SourceReference</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>OccurredAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.message_citations_organizations && Array.isArray(organizations.message_citations_organizations) &&
                              organizations.message_citations_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/message_citations/message_citations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="source_type">
                                        { item.source_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="source_label">
                                        { item.source_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="source_reference">
                                        { item.source_reference }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="occurred_at">
                                        { dataFormatter.dateTimeFormatter(item.occurred_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.message_citations_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Files_library organizations</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>
                            {organizations.files_library_organizations && Array.isArray(organizations.files_library_organizations) &&
                              organizations.files_library_organizations.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>
                        {!organizations?.files_library_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Sync_jobs organizations</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>
                            {organizations.sync_jobs_organizations && Array.isArray(organizations.sync_jobs_organizations) &&
                              organizations.sync_jobs_organizations.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>
                        {!organizations?.sync_jobs_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                

                <BaseDivider />

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

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

export default OrganizationsView;