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'}>Organization_memberships Organization</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>JoinedAt</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.organization_memberships_organization && Array.isArray(organizations.organization_memberships_organization) &&
                              organizations.organization_memberships_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/organization_memberships/organization_memberships-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="member_role">
                                        { item.member_role }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="joined_at">
                                        { dataFormatter.dateTimeFormatter(item.joined_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.organization_memberships_organization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Projects Organization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ProjectName</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Visibility</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LastActivityAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.projects_organization && Array.isArray(organizations.projects_organization) &&
                              organizations.projects_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/projects/projects-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="visibility">
                                        { item.visibility }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_activity_at">
                                        { dataFormatter.dateTimeFormatter(item.last_activity_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.projects_organization?.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>Status</th>
                                
                                
                                
                                <th>LastOpenedAt</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="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_opened_at">
                                        { dataFormatter.dateTimeFormatter(item.last_opened_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'}>Llm_providers organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>ProviderName</th>
                                
                                
                                
                                <th>BaseURL</th>
                                
                                
                                
                                <th>ProviderType</th>
                                
                                
                                
                                <th>RegionPolicy</th>
                                
                                
                                
                                <th>SupportsStreaming</th>
                                
                                
                                
                                <th>SupportsTools</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.llm_providers_organizations && Array.isArray(organizations.llm_providers_organizations) &&
                              organizations.llm_providers_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/llm_providers/llm_providers-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_url">
                                        { item.base_url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="provider_type">
                                        { item.provider_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="region_policy">
                                        { item.region_policy }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="supports_streaming">
                                        { dataFormatter.booleanFormatter(item.supports_streaming) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="supports_tools">
                                        { dataFormatter.booleanFormatter(item.supports_tools) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.llm_providers_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Llm_models organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ModelName</th>
                                
                                
                                
                                <th>ModelCode</th>
                                
                                
                                
                                <th>MaxInputTokens</th>
                                
                                
                                
                                <th>MaxOutputTokens</th>
                                
                                
                                
                                <th>SupportsVision</th>
                                
                                
                                
                                <th>SupportsFunctionCalling</th>
                                
                                
                                
                                <th>PricePerMillionInputTokens</th>
                                
                                
                                
                                <th>PricePerMillionOutputTokens</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.llm_models_organizations && Array.isArray(organizations.llm_models_organizations) &&
                              organizations.llm_models_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/llm_models/llm_models-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="model_code">
                                        { item.model_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_input_tokens">
                                        { item.max_input_tokens }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_output_tokens">
                                        { item.max_output_tokens }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="supports_vision">
                                        { dataFormatter.booleanFormatter(item.supports_vision) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="supports_function_calling">
                                        { dataFormatter.booleanFormatter(item.supports_function_calling) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="price_per_million_input_tokens">
                                        { item.price_per_million_input_tokens }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="price_per_million_output_tokens">
                                        { item.price_per_million_output_tokens }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.llm_models_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Llm_api_keys organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Label</th>
                                
                                
                                
                                <th>KeyFingerprint</th>
                                
                                
                                
                                <th>KeyStatus</th>
                                
                                
                                
                                <th>LastRotatedAt</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>IsPrimary</th>
                                
                                
                                
                                <th>RequestsPerMinuteLimit</th>
                                
                                
                                
                                <th>DailyRequestLimit</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.llm_api_keys_organizations && Array.isArray(organizations.llm_api_keys_organizations) &&
                              organizations.llm_api_keys_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/llm_api_keys/llm_api_keys-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="label">
                                        { item.label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="key_fingerprint">
                                        { item.key_fingerprint }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="key_status">
                                        { item.key_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_rotated_at">
                                        { dataFormatter.dateTimeFormatter(item.last_rotated_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_primary">
                                        { dataFormatter.booleanFormatter(item.is_primary) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="requests_per_minute_limit">
                                        { item.requests_per_minute_limit }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="daily_request_limit">
                                        { item.daily_request_limit }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.llm_api_keys_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Key_rotation_policies organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PolicyName</th>
                                
                                
                                
                                <th>Strategy</th>
                                
                                
                                
                                <th>RotateEverySeconds</th>
                                
                                
                                
                                <th>AutoDisableOnErrors</th>
                                
                                
                                
                                <th>ErrorThreshold</th>
                                
                                
                                
                                <th>CooldownSeconds</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.key_rotation_policies_organizations && Array.isArray(organizations.key_rotation_policies_organizations) &&
                              organizations.key_rotation_policies_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/key_rotation_policies/key_rotation_policies-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="strategy">
                                        { item.strategy }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rotate_every_seconds">
                                        { item.rotate_every_seconds }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="auto_disable_on_errors">
                                        { dataFormatter.booleanFormatter(item.auto_disable_on_errors) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_threshold">
                                        { item.error_threshold }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cooldown_seconds">
                                        { item.cooldown_seconds }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.key_rotation_policies_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Prompt_templates Organization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>TemplateName</th>
                                
                                
                                
                                <th>Category</th>
                                
                                
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                                
                                <th>Version</th>
                                
                                
                                
                                <th>PublishedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.prompt_templates_organization && Array.isArray(organizations.prompt_templates_organization) &&
                              organizations.prompt_templates_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/prompt_templates/prompt_templates-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="category">
                                        { item.category }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="version">
                                        { item.version }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="published_at">
                                        { dataFormatter.dateTimeFormatter(item.published_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.prompt_templates_organization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Chats organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>ChatTitle</th>
                                
                                
                                
                                <th>ChatStatus</th>
                                
                                
                                
                                
                                
                                <th>IsEncryptedE2EE</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>LastMessageAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.chats_organizations && Array.isArray(organizations.chats_organizations) &&
                              organizations.chats_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/chats/chats-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="chat_status">
                                        { item.chat_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_encrypted_e2ee">
                                        { dataFormatter.booleanFormatter(item.is_encrypted_e2ee) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_message_at">
                                        { dataFormatter.dateTimeFormatter(item.last_message_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.chats_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>SenderType</th>
                                
                                
                                
                                <th>SenderLabel</th>
                                
                                
                                
                                <th>ContentCiphertext</th>
                                
                                
                                
                                <th>ContentPreview</th>
                                
                                
                                
                                <th>EncryptionKeyId</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>TokenCountInput</th>
                                
                                
                                
                                <th>TokenCountOutput</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="sender_type">
                                        { item.sender_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sender_label">
                                        { item.sender_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content_ciphertext">
                                        { item.content_ciphertext }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content_preview">
                                        { item.content_preview }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="encryption_key_id">
                                        { item.encryption_key_id }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="token_count_input">
                                        { item.token_count_input }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="token_count_output">
                                        { item.token_count_output }
                                    </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'}>Encryption_sessions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>SessionKeyId</th>
                                
                                
                                
                                <th>Algorithm</th>
                                
                                
                                
                                <th>KeyLengthBits</th>
                                
                                
                                
                                <th>ValidFrom</th>
                                
                                
                                
                                <th>ValidUntil</th>
                                
                                
                                
                                <th>IsDiscarded</th>
                                
                                
                                
                                <th>DiscardedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.encryption_sessions_organizations && Array.isArray(organizations.encryption_sessions_organizations) &&
                              organizations.encryption_sessions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/encryption_sessions/encryption_sessions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="session_key_id">
                                        { item.session_key_id }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="algorithm">
                                        { item.algorithm }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="key_length_bits">
                                        { item.key_length_bits }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="valid_from">
                                        { dataFormatter.dateTimeFormatter(item.valid_from) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="valid_until">
                                        { dataFormatter.dateTimeFormatter(item.valid_until) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_discarded">
                                        { dataFormatter.booleanFormatter(item.is_discarded) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="discarded_at">
                                        { dataFormatter.dateTimeFormatter(item.discarded_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.encryption_sessions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Code_repositories organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>RepositoryName</th>
                                
                                
                                
                                <th>RepositoryType</th>
                                
                                
                                
                                <th>RemoteURL</th>
                                
                                
                                
                                <th>DefaultBranch</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LastSyncAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.code_repositories_organizations && Array.isArray(organizations.code_repositories_organizations) &&
                              organizations.code_repositories_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/code_repositories/code_repositories-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="repo_type">
                                        { item.repo_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="remote_url">
                                        { item.remote_url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="default_branch">
                                        { item.default_branch }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_sync_at">
                                        { dataFormatter.dateTimeFormatter(item.last_sync_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.code_repositories_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Code_files organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Path</th>
                                
                                
                                
                                <th>Language</th>
                                
                                
                                
                                <th>Content</th>
                                
                                
                                
                                <th>ContentHash</th>
                                
                                
                                
                                <th>LastModifiedAt</th>
                                
                                
                                
                                <th>IsBinary</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.code_files_organizations && Array.isArray(organizations.code_files_organizations) &&
                              organizations.code_files_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/code_files/code_files-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="path">
                                        { item.path }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="language">
                                        { item.language }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content">
                                        { item.content }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="content_hash">
                                        { item.content_hash }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_modified_at">
                                        { dataFormatter.dateTimeFormatter(item.last_modified_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_binary">
                                        { dataFormatter.booleanFormatter(item.is_binary) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.code_files_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Code_change_sets organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>ChangeSetTitle</th>
                                
                                
                                
                                <th>Summary</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>CreatedAtTime</th>
                                
                                
                                
                                <th>AppliedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.code_change_sets_organizations && Array.isArray(organizations.code_change_sets_organizations) &&
                              organizations.code_change_sets_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/code_change_sets/code_change_sets-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="summary">
                                        { item.summary }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="created_at_time">
                                        { dataFormatter.dateTimeFormatter(item.created_at_time) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="applied_at">
                                        { dataFormatter.dateTimeFormatter(item.applied_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.code_change_sets_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Code_patches organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>FilePath</th>
                                
                                
                                
                                <th>ChangeType</th>
                                
                                
                                
                                <th>DiffText</th>
                                
                                
                                
                                <th>AppliedSuccessfully</th>
                                
                                
                                
                                <th>ErrorMessage</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.code_patches_organizations && Array.isArray(organizations.code_patches_organizations) &&
                              organizations.code_patches_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/code_patches/code_patches-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="file_path">
                                        { item.file_path }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="change_type">
                                        { item.change_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="diff_text">
                                        { item.diff_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="applied_successfully">
                                        { dataFormatter.booleanFormatter(item.applied_successfully) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_message">
                                        { item.error_message }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.code_patches_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Build_jobs organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>BuildName</th>
                                
                                
                                
                                <th>TargetPlatform</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>QueuedAt</th>
                                
                                
                                
                                <th>StartedAt</th>
                                
                                
                                
                                <th>FinishedAt</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.build_jobs_organizations && Array.isArray(organizations.build_jobs_organizations) &&
                              organizations.build_jobs_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/build_jobs/build_jobs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="target_platform">
                                        { item.target_platform }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="queued_at">
                                        { dataFormatter.dateTimeFormatter(item.queued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="started_at">
                                        { dataFormatter.dateTimeFormatter(item.started_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="finished_at">
                                        { dataFormatter.dateTimeFormatter(item.finished_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.build_jobs_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Build_pipelines Organization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PipelineName</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>PipelineType</th>
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                                
                                <th>ConfigYAML</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.build_pipelines_organization && Array.isArray(organizations.build_pipelines_organization) &&
                              organizations.build_pipelines_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/build_pipelines/build_pipelines-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="pipeline_type">
                                        { item.pipeline_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="config_yaml">
                                        { item.config_yaml }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.build_pipelines_organization?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Build_artifacts organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ArtifactType</th>
                                
                                
                                
                                <th>FileName</th>
                                
                                
                                
                                
                                
                                <th>DownloadURL</th>
                                
                                
                                
                                <th>ChecksumSHA256</th>
                                
                                
                                
                                <th>GeneratedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.build_artifacts_organizations && Array.isArray(organizations.build_artifacts_organizations) &&
                              organizations.build_artifacts_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/build_artifacts/build_artifacts-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="artifact_type">
                                        { item.artifact_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="file_name">
                                        { item.file_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="download_url">
                                        { item.download_url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="checksum_sha256">
                                        { item.checksum_sha256 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="generated_at">
                                        { dataFormatter.dateTimeFormatter(item.generated_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.build_artifacts_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Web_search_queries organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>QueryText</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>RequestedAt</th>
                                
                                
                                
                                <th>CompletedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.web_search_queries_organizations && Array.isArray(organizations.web_search_queries_organizations) &&
                              organizations.web_search_queries_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/web_search_queries/web_search_queries-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="query_text">
                                        { item.query_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="requested_at">
                                        { dataFormatter.dateTimeFormatter(item.requested_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="completed_at">
                                        { dataFormatter.dateTimeFormatter(item.completed_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.web_search_queries_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Web_search_results organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>URL</th>
                                
                                
                                
                                <th>Snippet</th>
                                
                                
                                
                                <th>FetchedAt</th>
                                
                                
                                
                                <th>Rank</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.web_search_results_organizations && Array.isArray(organizations.web_search_results_organizations) &&
                              organizations.web_search_results_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/web_search_results/web_search_results-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="url">
                                        { item.url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="snippet">
                                        { item.snippet }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="fetched_at">
                                        { dataFormatter.dateTimeFormatter(item.fetched_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rank">
                                        { item.rank }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.web_search_results_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>System_health_checks organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>Component</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LatencyMs</th>
                                
                                
                                
                                <th>ErrorRatePercent</th>
                                
                                
                                
                                <th>CheckedAt</th>
                                
                                
                                
                                <th>Details</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.system_health_checks_organizations && Array.isArray(organizations.system_health_checks_organizations) &&
                              organizations.system_health_checks_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/system_health_checks/system_health_checks-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="component">
                                        { item.component }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="latency_ms">
                                        { item.latency_ms }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="error_rate_percent">
                                        { item.error_rate_percent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="checked_at">
                                        { dataFormatter.dateTimeFormatter(item.checked_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="details">
                                        { item.details }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.system_health_checks_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Audit_events Organization</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Action</th>
                                
                                
                                
                                <th>EntityName</th>
                                
                                
                                
                                <th>EntityKey</th>
                                
                                
                                
                                <th>Severity</th>
                                
                                
                                
                                <th>OccurredAt</th>
                                
                                
                                
                                <th>MetadataJSON</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.audit_events_organization && Array.isArray(organizations.audit_events_organization) &&
                              organizations.audit_events_organization.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/audit_events/audit_events-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="action">
                                        { item.action }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entity_name">
                                        { item.entity_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entity_key">
                                        { item.entity_key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="severity">
                                        { item.severity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="occurred_at">
                                        { dataFormatter.dateTimeFormatter(item.occurred_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="metadata_json">
                                        { item.metadata_json }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.audit_events_organization?.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;