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/schools/schoolsSlice';
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 SchoolsView = () => {
  const router = useRouter();
  const dispatch = useAppDispatch();
  const { schools } = useAppSelector((state) => state.schools);

  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 schools')}</title>
      </Head>
      <SectionMain>
        <SectionTitleLineWithButton
          icon={mdiChartTimelineVariant}
          title={removeLastCharacter('View schools')}
          main
        >
          <BaseButton
            color='info'
            label='Edit'
            href={`/schools/schools-edit/?id=${id}`}
          />
        </SectionTitleLineWithButton>
        <CardBox>
          <div className={'mb-4'}>
            <p className={'block font-bold mb-2'}>Name</p>
            <p>{schools?.name}</p>
          </div>

          <>
            <p className={'block font-bold mb-2'}>Users Schools</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>
                    {schools.users_schools &&
                      Array.isArray(schools.users_schools) &&
                      schools.users_schools.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>
              {!schools?.users_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Activity_logs schools</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>EntityType</th>

                      <th>EntityID</th>

                      <th>Timestamp</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.activity_logs_schools &&
                      Array.isArray(schools.activity_logs_schools) &&
                      schools.activity_logs_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/activity_logs/activity_logs-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='action'>{item.action}</td>

                          <td data-label='entity_type'>{item.entity_type}</td>

                          <td data-label='entity_id'>{item.entity_id}</td>

                          <td data-label='timestamp'>
                            {dataFormatter.dateTimeFormatter(item.timestamp)}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.activity_logs_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>
              Assignment_submissions schools
            </p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>SubmissionDate</th>

                      <th>Content</th>

                      <th>Grade</th>

                      <th>Feedback</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.assignment_submissions_schools &&
                      Array.isArray(schools.assignment_submissions_schools) &&
                      schools.assignment_submissions_schools.map(
                        (item: any) => (
                          <tr
                            key={item.id}
                            onClick={() =>
                              router.push(
                                `/assignment_submissions/assignment_submissions-view/?id=${item.id}`,
                              )
                            }
                          >
                            <td data-label='submission_date'>
                              {dataFormatter.dateTimeFormatter(
                                item.submission_date,
                              )}
                            </td>

                            <td data-label='content'>{item.content}</td>

                            <td data-label='grade'>{item.grade}</td>

                            <td data-label='feedback'>{item.feedback}</td>
                          </tr>
                        ),
                      )}
                  </tbody>
                </table>
              </div>
              {!schools?.assignment_submissions_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Assignments schools</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>Description</th>

                      <th>DueDate</th>

                      <th>AttachmentURL</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.assignments_schools &&
                      Array.isArray(schools.assignments_schools) &&
                      schools.assignments_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/assignments/assignments-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='title'>{item.title}</td>

                          <td data-label='description'>{item.description}</td>

                          <td data-label='due_date'>
                            {dataFormatter.dateTimeFormatter(item.due_date)}
                          </td>

                          <td data-label='attachment_url'>
                            {item.attachment_url}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.assignments_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Bills School</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>Amount</th>

                      <th>BillMonth</th>

                      <th>Category</th>

                      <th>UploadURL</th>

                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.bills_school &&
                      Array.isArray(schools.bills_school) &&
                      schools.bills_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/bills/bills-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='title'>{item.title}</td>

                          <td data-label='amount'>{item.amount}</td>

                          <td data-label='bill_month'>{item.bill_month}</td>

                          <td data-label='category'>{item.category}</td>

                          <td data-label='upload_url'>{item.upload_url}</td>

                          <td data-label='status'>{item.status}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.bills_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Bills schools</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>Amount</th>

                      <th>BillMonth</th>

                      <th>Category</th>

                      <th>UploadURL</th>

                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.bills_schools &&
                      Array.isArray(schools.bills_schools) &&
                      schools.bills_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/bills/bills-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='title'>{item.title}</td>

                          <td data-label='amount'>{item.amount}</td>

                          <td data-label='bill_month'>{item.bill_month}</td>

                          <td data-label='category'>{item.category}</td>

                          <td data-label='upload_url'>{item.upload_url}</td>

                          <td data-label='status'>{item.status}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.bills_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Class_messages schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Content</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.class_messages_schools &&
                      Array.isArray(schools.class_messages_schools) &&
                      schools.class_messages_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/class_messages/class_messages-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='content'>{item.content}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.class_messages_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Class_subjects schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr></tr>
                  </thead>
                  <tbody>
                    {schools.class_subjects_schools &&
                      Array.isArray(schools.class_subjects_schools) &&
                      schools.class_subjects_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/class_subjects/class_subjects-view/?id=${item.id}`,
                            )
                          }
                        ></tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.class_subjects_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Classes School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Name</th>

                      <th>Section</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.classes_school &&
                      Array.isArray(schools.classes_school) &&
                      schools.classes_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/classes/classes-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='name'>{item.name}</td>

                          <td data-label='section'>{item.section}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.classes_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Classes schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Name</th>

                      <th>Section</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.classes_schools &&
                      Array.isArray(schools.classes_schools) &&
                      schools.classes_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/classes/classes-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='name'>{item.name}</td>

                          <td data-label='section'>{item.section}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.classes_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Exam_subjects schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>ExamDate</th>

                      <th>MaxMarks</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.exam_subjects_schools &&
                      Array.isArray(schools.exam_subjects_schools) &&
                      schools.exam_subjects_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/exam_subjects/exam_subjects-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='exam_date'>
                            {dataFormatter.dateTimeFormatter(item.exam_date)}
                          </td>

                          <td data-label='max_marks'>{item.max_marks}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.exam_subjects_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Exams School</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>StartDate</th>

                      <th>EndDate</th>

                      <th>Term</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.exams_school &&
                      Array.isArray(schools.exams_school) &&
                      schools.exams_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/exams/exams-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='title'>{item.title}</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='term'>{item.term}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.exams_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Exams schools</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>StartDate</th>

                      <th>EndDate</th>

                      <th>Term</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.exams_schools &&
                      Array.isArray(schools.exams_schools) &&
                      schools.exams_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/exams/exams-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='title'>{item.title}</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='term'>{item.term}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.exams_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Fee_payments schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>AmountPaid</th>

                      <th>PaymentDate</th>

                      <th>ReceiptURL</th>

                      <th>Term</th>

                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.fee_payments_schools &&
                      Array.isArray(schools.fee_payments_schools) &&
                      schools.fee_payments_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/fee_payments/fee_payments-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='amount_paid'>{item.amount_paid}</td>

                          <td data-label='payment_date'>
                            {dataFormatter.dateTimeFormatter(item.payment_date)}
                          </td>

                          <td data-label='receipt_url'>{item.receipt_url}</td>

                          <td data-label='term'>{item.term}</td>

                          <td data-label='status'>{item.status}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.fee_payments_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Fee_structures School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Term</th>

                      <th>Amount</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.fee_structures_school &&
                      Array.isArray(schools.fee_structures_school) &&
                      schools.fee_structures_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/fee_structures/fee_structures-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='term'>{item.term}</td>

                          <td data-label='amount'>{item.amount}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.fee_structures_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Fee_structures schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Term</th>

                      <th>Amount</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.fee_structures_schools &&
                      Array.isArray(schools.fee_structures_schools) &&
                      schools.fee_structures_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/fee_structures/fee_structures-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='term'>{item.term}</td>

                          <td data-label='amount'>{item.amount}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.fee_structures_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Lesson_plans schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>WeekStartDate</th>

                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.lesson_plans_schools &&
                      Array.isArray(schools.lesson_plans_schools) &&
                      schools.lesson_plans_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/lesson_plans/lesson_plans-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='week_start_date'>
                            {dataFormatter.dateTimeFormatter(
                              item.week_start_date,
                            )}
                          </td>

                          <td data-label='status'>{item.status}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.lesson_plans_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Login_logs schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>LoginTime</th>

                      <th>IPAddress</th>

                      <th>DeviceInfo</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.login_logs_schools &&
                      Array.isArray(schools.login_logs_schools) &&
                      schools.login_logs_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/login_logs/login_logs-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='login_time'>
                            {dataFormatter.dateTimeFormatter(item.login_time)}
                          </td>

                          <td data-label='ip_address'>{item.ip_address}</td>

                          <td data-label='device_info'>{item.device_info}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.login_logs_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Marks schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>MarksObtained</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.marks_schools &&
                      Array.isArray(schools.marks_schools) &&
                      schools.marks_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/marks/marks-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='marks_obtained'>
                            {item.marks_obtained}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.marks_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Messages School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>ReceiverRole</th>

                      <th>MessageType</th>

                      <th>Content</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.messages_school &&
                      Array.isArray(schools.messages_school) &&
                      schools.messages_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/messages/messages-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='receiver_role'>
                            {item.receiver_role}
                          </td>

                          <td data-label='message_type'>{item.message_type}</td>

                          <td data-label='content'>{item.content}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.messages_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Messages schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>ReceiverRole</th>

                      <th>MessageType</th>

                      <th>Content</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.messages_schools &&
                      Array.isArray(schools.messages_schools) &&
                      schools.messages_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/messages/messages-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='receiver_role'>
                            {item.receiver_role}
                          </td>

                          <td data-label='message_type'>{item.message_type}</td>

                          <td data-label='content'>{item.content}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.messages_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Parents schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FullName</th>

                      <th>PhoneNumber</th>

                      <th>Address</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.parents_schools &&
                      Array.isArray(schools.parents_schools) &&
                      schools.parents_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(`/parents/parents-view/?id=${item.id}`)
                          }
                        >
                          <td data-label='full_name'>{item.full_name}</td>

                          <td data-label='phone_number'>{item.phone_number}</td>

                          <td data-label='address'>{item.address}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.parents_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Period_settings School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>TotalPeriodsPerDay</th>

                      <th>PeriodDuration(minutes)</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.period_settings_school &&
                      Array.isArray(schools.period_settings_school) &&
                      schools.period_settings_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/period_settings/period_settings-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='total_periods_per_day'>
                            {item.total_periods_per_day}
                          </td>

                          <td data-label='period_duration'>
                            {item.period_duration}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.period_settings_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Period_settings schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>TotalPeriodsPerDay</th>

                      <th>PeriodDuration(minutes)</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.period_settings_schools &&
                      Array.isArray(schools.period_settings_schools) &&
                      schools.period_settings_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/period_settings/period_settings-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='total_periods_per_day'>
                            {item.total_periods_per_day}
                          </td>

                          <td data-label='period_duration'>
                            {item.period_duration}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.period_settings_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>School_admins School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FullName</th>

                      <th>PhoneNumber</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.school_admins_school &&
                      Array.isArray(schools.school_admins_school) &&
                      schools.school_admins_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/school_admins/school_admins-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='full_name'>{item.full_name}</td>

                          <td data-label='phone_number'>{item.phone_number}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.school_admins_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>School_admins schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FullName</th>

                      <th>PhoneNumber</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.school_admins_schools &&
                      Array.isArray(schools.school_admins_schools) &&
                      schools.school_admins_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/school_admins/school_admins-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='full_name'>{item.full_name}</td>

                          <td data-label='phone_number'>{item.phone_number}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.school_admins_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Student_attendance schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Date</th>

                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.student_attendance_schools &&
                      Array.isArray(schools.student_attendance_schools) &&
                      schools.student_attendance_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/student_attendance/student_attendance-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='date'>
                            {dataFormatter.dateTimeFormatter(item.date)}
                          </td>

                          <td data-label='status'>{item.status}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.student_attendance_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Students School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FullName</th>

                      <th>DateofBirth</th>

                      <th>Gender</th>

                      <th>AdmissionDate</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.students_school &&
                      Array.isArray(schools.students_school) &&
                      schools.students_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/students/students-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='full_name'>{item.full_name}</td>

                          <td data-label='dob'>
                            {dataFormatter.dateTimeFormatter(item.dob)}
                          </td>

                          <td data-label='gender'>{item.gender}</td>

                          <td data-label='admission_date'>
                            {dataFormatter.dateTimeFormatter(
                              item.admission_date,
                            )}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.students_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Students schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FullName</th>

                      <th>DateofBirth</th>

                      <th>Gender</th>

                      <th>AdmissionDate</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.students_schools &&
                      Array.isArray(schools.students_schools) &&
                      schools.students_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/students/students-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='full_name'>{item.full_name}</td>

                          <td data-label='dob'>
                            {dataFormatter.dateTimeFormatter(item.dob)}
                          </td>

                          <td data-label='gender'>{item.gender}</td>

                          <td data-label='admission_date'>
                            {dataFormatter.dateTimeFormatter(
                              item.admission_date,
                            )}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.students_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Subjects School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Name</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.subjects_school &&
                      Array.isArray(schools.subjects_school) &&
                      schools.subjects_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/subjects/subjects-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='name'>{item.name}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.subjects_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Subjects schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Name</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.subjects_schools &&
                      Array.isArray(schools.subjects_schools) &&
                      schools.subjects_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/subjects/subjects-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='name'>{item.name}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.subjects_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Teacher_attendance School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Date</th>

                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.teacher_attendance_school &&
                      Array.isArray(schools.teacher_attendance_school) &&
                      schools.teacher_attendance_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/teacher_attendance/teacher_attendance-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='date'>
                            {dataFormatter.dateTimeFormatter(item.date)}
                          </td>

                          <td data-label='status'>{item.status}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.teacher_attendance_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Teacher_attendance schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>Date</th>

                      <th>Status</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.teacher_attendance_schools &&
                      Array.isArray(schools.teacher_attendance_schools) &&
                      schools.teacher_attendance_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/teacher_attendance/teacher_attendance-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='date'>
                            {dataFormatter.dateTimeFormatter(item.date)}
                          </td>

                          <td data-label='status'>{item.status}</td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.teacher_attendance_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Teachers School</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FullName</th>

                      <th>SubjectSpecialization</th>

                      <th>PhoneNumber</th>

                      <th>JoiningDate</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.teachers_school &&
                      Array.isArray(schools.teachers_school) &&
                      schools.teachers_school.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/teachers/teachers-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='full_name'>{item.full_name}</td>

                          <td data-label='subject_specialization'>
                            {item.subject_specialization}
                          </td>

                          <td data-label='phone_number'>{item.phone_number}</td>

                          <td data-label='joining_date'>
                            {dataFormatter.dateTimeFormatter(item.joining_date)}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.teachers_school?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Teachers schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>FullName</th>

                      <th>SubjectSpecialization</th>

                      <th>PhoneNumber</th>

                      <th>JoiningDate</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.teachers_schools &&
                      Array.isArray(schools.teachers_schools) &&
                      schools.teachers_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/teachers/teachers-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='full_name'>{item.full_name}</td>

                          <td data-label='subject_specialization'>
                            {item.subject_specialization}
                          </td>

                          <td data-label='phone_number'>{item.phone_number}</td>

                          <td data-label='joining_date'>
                            {dataFormatter.dateTimeFormatter(item.joining_date)}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.teachers_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <>
            <p className={'block font-bold mb-2'}>Timetables schools</p>
            <CardBox
              className='mb-6 border border-gray-300 rounded overflow-hidden'
              hasTable
            >
              <div className='overflow-x-auto'>
                <table>
                  <thead>
                    <tr>
                      <th>DayofWeek</th>

                      <th>PeriodNumber</th>
                    </tr>
                  </thead>
                  <tbody>
                    {schools.timetables_schools &&
                      Array.isArray(schools.timetables_schools) &&
                      schools.timetables_schools.map((item: any) => (
                        <tr
                          key={item.id}
                          onClick={() =>
                            router.push(
                              `/timetables/timetables-view/?id=${item.id}`,
                            )
                          }
                        >
                          <td data-label='day_of_week'>{item.day_of_week}</td>

                          <td data-label='period_number'>
                            {item.period_number}
                          </td>
                        </tr>
                      ))}
                  </tbody>
                </table>
              </div>
              {!schools?.timetables_schools?.length && (
                <div className={'text-center py-4'}>No data</div>
              )}
            </CardBox>
          </>

          <BaseDivider />

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

SchoolsView.getLayout = function getLayout(page: ReactElement) {
  return (
    <LayoutAuthenticated permission={'READ_SCHOOLS'}>
      {page}
    </LayoutAuthenticated>
  );
};

export default SchoolsView;
