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'}>Companies organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>CompanyName</th>
                                
                                
                                
                                <th>TaxID</th>
                                
                                
                                
                                <th>RegistrationNumber</th>
                                
                                
                                
                                <th>CompanyEmail</th>
                                
                                
                                
                                <th>CompanyPhone</th>
                                
                                
                                
                                <th>Website</th>
                                
                                
                                
                                <th>AddressLine1</th>
                                
                                
                                
                                <th>AddressLine2</th>
                                
                                
                                
                                <th>City</th>
                                
                                
                                
                                <th>State/Province</th>
                                
                                
                                
                                <th>PostalCode</th>
                                
                                
                                
                                <th>Country</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.companies_organizations && Array.isArray(organizations.companies_organizations) &&
                              organizations.companies_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/companies/companies-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_id">
                                        { item.tax_id }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="registration_number">
                                        { item.registration_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="website">
                                        { item.website }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_line1">
                                        { item.address_line1 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_line2">
                                        { item.address_line2 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="city">
                                        { item.city }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="state">
                                        { item.state }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="postal_code">
                                        { item.postal_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="country">
                                        { item.country }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.companies_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Role_permissions organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.role_permissions_organizations && Array.isArray(organizations.role_permissions_organizations) &&
                              organizations.role_permissions_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/role_permissions/role_permissions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.role_permissions_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>User_roles organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.user_roles_organizations && Array.isArray(organizations.user_roles_organizations) &&
                              organizations.user_roles_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/user_roles/user_roles-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.user_roles_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Departments organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>DepartmentName</th>
                                
                                
                                
                                <th>DepartmentCode</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.departments_organizations && Array.isArray(organizations.departments_organizations) &&
                              organizations.departments_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/departments/departments-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.departments_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Job_titles organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>JobTitle</th>
                                
                                
                                
                                <th>JobCode</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.job_titles_organizations && Array.isArray(organizations.job_titles_organizations) &&
                              organizations.job_titles_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/job_titles/job_titles-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.job_titles_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Work_locations organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>LocationName</th>
                                
                                
                                
                                <th>LocationCode</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>Timezone</th>
                                
                                
                                
                                
                                
                                <th>LocationType</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.work_locations_organizations && Array.isArray(organizations.work_locations_organizations) &&
                              organizations.work_locations_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/work_locations/work_locations-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="timezone">
                                        { item.timezone }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="location_type">
                                        { item.location_type }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.work_locations_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Employees organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>EmployeeNumber</th>
                                
                                
                                
                                <th>FirstName</th>
                                
                                
                                
                                <th>LastName</th>
                                
                                
                                
                                <th>PreferredName</th>
                                
                                
                                
                                <th>WorkEmail</th>
                                
                                
                                
                                <th>Phone</th>
                                
                                
                                
                                <th>NationalID</th>
                                
                                
                                
                                <th>DateofBirth</th>
                                
                                
                                
                                <th>Gender</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>HireDate</th>
                                
                                
                                
                                <th>TerminationDate</th>
                                
                                
                                
                                <th>EmploymentStatus</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>EmploymentType</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.employees_organizations && Array.isArray(organizations.employees_organizations) &&
                              organizations.employees_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/employees/employees-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="employee_number">
                                        { item.employee_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="first_name">
                                        { item.first_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="last_name">
                                        { item.last_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="preferred_name">
                                        { item.preferred_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone">
                                        { item.phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="national_id">
                                        { item.national_id }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="date_of_birth">
                                        { dataFormatter.dateTimeFormatter(item.date_of_birth) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gender">
                                        { item.gender }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="hire_date">
                                        { dataFormatter.dateTimeFormatter(item.hire_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="termination_date">
                                        { dataFormatter.dateTimeFormatter(item.termination_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="employment_status">
                                        { item.employment_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="employment_type">
                                        { item.employment_type }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.employees_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Employment_contracts organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>ContractNumber</th>
                                
                                
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>ContractType</th>
                                
                                
                                
                                <th>BaseSalary</th>
                                
                                
                                
                                <th>SalaryPeriod</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.employment_contracts_organizations && Array.isArray(organizations.employment_contracts_organizations) &&
                              organizations.employment_contracts_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/employment_contracts/employment_contracts-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="contract_number">
                                        { item.contract_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="start_date">
                                        { dataFormatter.dateTimeFormatter(item.start_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_date">
                                        { dataFormatter.dateTimeFormatter(item.end_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="contract_type">
                                        { item.contract_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_salary">
                                        { item.base_salary }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="salary_period">
                                        { item.salary_period }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.employment_contracts_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Leave_types organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>LeaveType</th>
                                
                                
                                
                                <th>LeaveCode</th>
                                
                                
                                
                                
                                
                                <th>RequiresApproval</th>
                                
                                
                                
                                <th>RequiresAttachment</th>
                                
                                
                                
                                <th>DefaultAllowance(Days)</th>
                                
                                
                                
                                <th>Unit</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.leave_types_organizations && Array.isArray(organizations.leave_types_organizations) &&
                              organizations.leave_types_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/leave_types/leave_types-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="requires_approval">
                                        { dataFormatter.booleanFormatter(item.requires_approval) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="requires_attachment">
                                        { dataFormatter.booleanFormatter(item.requires_attachment) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="default_allowance_days">
                                        { item.default_allowance_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="unit">
                                        { item.unit }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.leave_types_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Leave_requests organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>StartAt</th>
                                
                                
                                
                                <th>EndAt</th>
                                
                                
                                
                                <th>Duration</th>
                                
                                
                                
                                <th>DurationUnit</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Reason</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>DecisionAt</th>
                                
                                
                                
                                <th>DecisionComment</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.leave_requests_organizations && Array.isArray(organizations.leave_requests_organizations) &&
                              organizations.leave_requests_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/leave_requests/leave_requests-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="start_at">
                                        { dataFormatter.dateTimeFormatter(item.start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_at">
                                        { dataFormatter.dateTimeFormatter(item.end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="duration">
                                        { item.duration }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="duration_unit">
                                        { item.duration_unit }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="decision_at">
                                        { dataFormatter.dateTimeFormatter(item.decision_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="decision_comment">
                                        { item.decision_comment }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.leave_requests_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Attendance_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>Description</th>
                                
                                
                                
                                <th>GraceMinutesLate</th>
                                
                                
                                
                                <th>GraceMinutesEarlyLeave</th>
                                
                                
                                
                                <th>RequireLocation</th>
                                
                                
                                
                                <th>RequireNoteonMissingPunch</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.attendance_policies_organizations && Array.isArray(organizations.attendance_policies_organizations) &&
                              organizations.attendance_policies_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/attendance_policies/attendance_policies-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="grace_minutes_late">
                                        { item.grace_minutes_late }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="grace_minutes_early_leave">
                                        { item.grace_minutes_early_leave }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="require_location">
                                        { dataFormatter.booleanFormatter(item.require_location) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="require_note_on_missing_punch">
                                        { dataFormatter.booleanFormatter(item.require_note_on_missing_punch) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.attendance_policies_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Work_schedules organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>ScheduleName</th>
                                
                                
                                
                                
                                
                                <th>ScheduleType</th>
                                
                                
                                
                                <th>WorkMinutesperDay</th>
                                
                                
                                
                                <th>BreakMinutesperDay</th>
                                
                                
                                
                                <th>EffectiveFrom</th>
                                
                                
                                
                                <th>EffectiveTo</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.work_schedules_organizations && Array.isArray(organizations.work_schedules_organizations) &&
                              organizations.work_schedules_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/work_schedules/work_schedules-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="schedule_type">
                                        { item.schedule_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="work_minutes_per_day">
                                        { item.work_minutes_per_day }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="break_minutes_per_day">
                                        { item.break_minutes_per_day }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="effective_from">
                                        { dataFormatter.dateTimeFormatter(item.effective_from) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="effective_to">
                                        { dataFormatter.dateTimeFormatter(item.effective_to) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.work_schedules_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Employee_schedule_assignments organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.employee_schedule_assignments_organizations && Array.isArray(organizations.employee_schedule_assignments_organizations) &&
                              organizations.employee_schedule_assignments_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/employee_schedule_assignments/employee_schedule_assignments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="start_date">
                                        { dataFormatter.dateTimeFormatter(item.start_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_date">
                                        { dataFormatter.dateTimeFormatter(item.end_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.employee_schedule_assignments_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Time_entries organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ClockInAt</th>
                                
                                
                                
                                <th>ClockOutAt</th>
                                
                                
                                
                                <th>ClockInSource</th>
                                
                                
                                
                                <th>ClockOutSource</th>
                                
                                
                                
                                <th>WorkedHours</th>
                                
                                
                                
                                <th>BreakHours</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Note</th>
                                
                                
                                
                                
                                
                                <th>ApprovedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.time_entries_organizations && Array.isArray(organizations.time_entries_organizations) &&
                              organizations.time_entries_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/time_entries/time_entries-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="clock_in_at">
                                        { dataFormatter.dateTimeFormatter(item.clock_in_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="clock_out_at">
                                        { dataFormatter.dateTimeFormatter(item.clock_out_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="clock_in_source">
                                        { item.clock_in_source }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="clock_out_source">
                                        { item.clock_out_source }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="worked_hours">
                                        { item.worked_hours }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="break_hours">
                                        { item.break_hours }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="note">
                                        { item.note }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="approved_at">
                                        { dataFormatter.dateTimeFormatter(item.approved_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.time_entries_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Holidays organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>HolidayName</th>
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>HolidayType</th>
                                
                                
                                
                                <th>IsPaid</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.holidays_organizations && Array.isArray(organizations.holidays_organizations) &&
                              organizations.holidays_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/holidays/holidays-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="start_date">
                                        { dataFormatter.dateTimeFormatter(item.start_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_date">
                                        { dataFormatter.dateTimeFormatter(item.end_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="holiday_type">
                                        { item.holiday_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_paid">
                                        { dataFormatter.booleanFormatter(item.is_paid) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.holidays_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Expense_categories organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>CategoryName</th>
                                
                                
                                
                                <th>CategoryCode</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.expense_categories_organizations && Array.isArray(organizations.expense_categories_organizations) &&
                              organizations.expense_categories_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/expense_categories/expense_categories-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.expense_categories_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Expense_claims organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>ExpenseDate</th>
                                
                                
                                
                                <th>Amount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>Merchant</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>DecisionAt</th>
                                
                                
                                
                                <th>DecisionComment</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.expense_claims_organizations && Array.isArray(organizations.expense_claims_organizations) &&
                              organizations.expense_claims_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/expense_claims/expense_claims-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="expense_date">
                                        { dataFormatter.dateTimeFormatter(item.expense_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="amount">
                                        { item.amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="merchant">
                                        { item.merchant }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="decision_at">
                                        { dataFormatter.dateTimeFormatter(item.decision_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="decision_comment">
                                        { item.decision_comment }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.expense_claims_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Documents organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>DocumentName</th>
                                
                                
                                
                                <th>DocumentType</th>
                                
                                
                                
                                
                                
                                <th>IssuedAt</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.documents_organizations && Array.isArray(organizations.documents_organizations) &&
                              organizations.documents_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/documents/documents-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="document_type">
                                        { item.document_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="issued_at">
                                        { dataFormatter.dateTimeFormatter(item.issued_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.documents_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Announcements 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>PublishAt</th>
                                
                                
                                
                                <th>ExpireAt</th>
                                
                                
                                
                                <th>Visibility</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.announcements_organizations && Array.isArray(organizations.announcements_organizations) &&
                              organizations.announcements_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/announcements/announcements-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="publish_at">
                                        { dataFormatter.dateTimeFormatter(item.publish_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expire_at">
                                        { dataFormatter.dateTimeFormatter(item.expire_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="visibility">
                                        { item.visibility }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.announcements_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Api_configs organizations</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ServiceName</th>
                                
                                
                                
                                <th>BaseURL</th>
                                
                                
                                
                                <th>APIKeyName</th>
                                
                                
                                
                                <th>APIKeyValue</th>
                                
                                
                                
                                <th>IsEnabled</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.api_configs_organizations && Array.isArray(organizations.api_configs_organizations) &&
                              organizations.api_configs_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/api_configs/api_configs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="service_name">
                                        { item.service_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_url">
                                        { item.base_url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="api_key_name">
                                        { item.api_key_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="api_key_value">
                                        { item.api_key_value }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_enabled">
                                        { dataFormatter.booleanFormatter(item.is_enabled) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.api_configs_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Audit_logs organizations</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>OccurredAt</th>
                                
                                
                                
                                <th>IPAddress</th>
                                
                                
                                
                                <th>UserAgent</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {organizations.audit_logs_organizations && Array.isArray(organizations.audit_logs_organizations) &&
                              organizations.audit_logs_organizations.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/audit_logs/audit_logs-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="occurred_at">
                                        { dataFormatter.dateTimeFormatter(item.occurred_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ip_address">
                                        { item.ip_address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="user_agent">
                                        { item.user_agent }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!organizations?.audit_logs_organizations?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                

                <BaseDivider />

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

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

export default OrganizationsView;