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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Phone Number</p>
                    <p>{users?.phoneNumber}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>E-Mail</p>
                    <p>{users?.email}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='Disabled'>
                    <SwitchField
                      field={{name: 'disabled', value: users?.disabled}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Avatar</p>
                    {users?.avatar?.length
                      ? (
                        <ImageField
                          name={'avatar'}
                          image={users?.avatar}
                          className='w-20 h-20'
                        />
                      ) : <p>No Avatar</p>
                    }
                </div>
              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>App Role</p>
                    
                    
                    
                    
                        <p>{users?.app_role?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>Custom Permissions</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>
                            {users.custom_permissions && Array.isArray(users.custom_permissions) &&
                              users.custom_permissions.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/permissions/permissions-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                  
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.custom_permissions?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Classrooms AdviserTeacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>ClassroomName</th>
                                
                                
                                
                                <th>SectionName</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>InviteCode</th>
                                
                                
                                
                                <th>InviteCodeExpiresAt</th>
                                
                                
                                
                                <th>InviteCodeEnabled</th>
                                
                                
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.classrooms_adviser_teacher && Array.isArray(users.classrooms_adviser_teacher) &&
                              users.classrooms_adviser_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/classrooms/classrooms-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="classroom_name">
                                        { item.classroom_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="section_name">
                                        { item.section_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="invite_code">
                                        { item.invite_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invite_code_expires_at">
                                        { dataFormatter.dateTimeFormatter(item.invite_code_expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="invite_code_enabled">
                                        { dataFormatter.booleanFormatter(item.invite_code_enabled) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.classrooms_adviser_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Classroom_memberships Student</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>JoinedAt</th>
                                
                                
                                
                                <th>MembershipStatus</th>
                                
                                
                                
                                <th>JoinMethod</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.classroom_memberships_student && Array.isArray(users.classroom_memberships_student) &&
                              users.classroom_memberships_student.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/classroom_memberships/classroom_memberships-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="joined_at">
                                        { dataFormatter.dateTimeFormatter(item.joined_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="membership_status">
                                        { item.membership_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="join_method">
                                        { item.join_method }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.classroom_memberships_student?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Teaching_assignments Teacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>AssignmentRole</th>
                                
                                
                                
                                <th>AssignedAt</th>
                                
                                
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.teaching_assignments_teacher && Array.isArray(users.teaching_assignments_teacher) &&
                              users.teaching_assignments_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/teaching_assignments/teaching_assignments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="assignment_role">
                                        { item.assignment_role }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="assigned_at">
                                        { dataFormatter.dateTimeFormatter(item.assigned_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.teaching_assignments_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                <>
                    <p className={'block font-bold mb-2'}>Teaching_assignments AssignedBy</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>AssignmentRole</th>
                                
                                
                                
                                <th>AssignedAt</th>
                                
                                
                                
                                
                                
                                <th>IsActive</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.teaching_assignments_assigned_by && Array.isArray(users.teaching_assignments_assigned_by) &&
                              users.teaching_assignments_assigned_by.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/teaching_assignments/teaching_assignments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="assignment_role">
                                        { item.assignment_role }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="assigned_at">
                                        { dataFormatter.dateTimeFormatter(item.assigned_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.teaching_assignments_assigned_by?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Homeworks Teacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>HomeworkTitle</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>AssignedAt</th>
                                
                                
                                
                                <th>DueAt</th>
                                
                                
                                
                                <th>LateUntilAt</th>
                                
                                
                                
                                <th>HomeworkStatus</th>
                                
                                
                                
                                <th>MaxScore</th>
                                
                                
                                
                                <th>AllowLate</th>
                                
                                
                                
                                
                                
                                <th>RequiresFaceVerification</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.homeworks_teacher && Array.isArray(users.homeworks_teacher) &&
                              users.homeworks_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/homeworks/homeworks-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="homework_title">
                                        { item.homework_title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="assigned_at">
                                        { dataFormatter.dateTimeFormatter(item.assigned_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_at">
                                        { dataFormatter.dateTimeFormatter(item.due_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="late_until_at">
                                        { dataFormatter.dateTimeFormatter(item.late_until_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="homework_status">
                                        { item.homework_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_score">
                                        { item.max_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="allow_late">
                                        { dataFormatter.booleanFormatter(item.allow_late) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="requires_face_verification">
                                        { dataFormatter.booleanFormatter(item.requires_face_verification) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.homeworks_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Homework_extensions CreatedBy</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>ExtensionScope</th>
                                
                                
                                
                                
                                
                                <th>ExtendedDueAt</th>
                                
                                
                                
                                <th>ExtendedLateUntilAt</th>
                                
                                
                                
                                <th>Reason</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.homework_extensions_created_by_user && Array.isArray(users.homework_extensions_created_by_user) &&
                              users.homework_extensions_created_by_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/homework_extensions/homework_extensions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="extension_scope">
                                        { item.extension_scope }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="extended_due_at">
                                        { dataFormatter.dateTimeFormatter(item.extended_due_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="extended_late_until_at">
                                        { dataFormatter.dateTimeFormatter(item.extended_late_until_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.homework_extensions_created_by_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Homework_submissions Student</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>SubmissionStatus</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>FaceVerifiedForSubmission</th>
                                
                                
                                
                                <th>FaceVerifiedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.homework_submissions_student && Array.isArray(users.homework_submissions_student) &&
                              users.homework_submissions_student.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/homework_submissions/homework_submissions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="submission_status">
                                        { item.submission_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="face_verified_for_submission">
                                        { dataFormatter.booleanFormatter(item.face_verified_for_submission) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="face_verified_at">
                                        { dataFormatter.dateTimeFormatter(item.face_verified_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.homework_submissions_student?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Submission_grades GradedByTeacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>GradedAt</th>
                                
                                
                                
                                <th>TotalScore</th>
                                
                                
                                
                                <th>MaxScoreSnapshot</th>
                                
                                
                                
                                <th>GradeStatus</th>
                                
                                
                                
                                
                                
                                <th>ReturnedToStudent</th>
                                
                                
                                
                                <th>ReturnedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.submission_grades_graded_by_teacher && Array.isArray(users.submission_grades_graded_by_teacher) &&
                              users.submission_grades_graded_by_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/submission_grades/submission_grades-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="graded_at">
                                        { dataFormatter.dateTimeFormatter(item.graded_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_score">
                                        { item.total_score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_score_snapshot">
                                        { item.max_score_snapshot }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="grade_status">
                                        { item.grade_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="returned_to_student">
                                        { dataFormatter.booleanFormatter(item.returned_to_student) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="returned_at">
                                        { dataFormatter.dateTimeFormatter(item.returned_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.submission_grades_graded_by_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Gradebooks OwnerTeacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>GradebookName</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Term</th>
                                
                                
                                
                                <th>StartAt</th>
                                
                                
                                
                                <th>EndAt</th>
                                
                                
                                
                                <th>IsPublished</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.gradebooks_owner_teacher && Array.isArray(users.gradebooks_owner_teacher) &&
                              users.gradebooks_owner_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/gradebooks/gradebooks-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="gradebook_name">
                                        { item.gradebook_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="term">
                                        { item.term }
                                    </td>
                                    
                                    
                                    
                                    <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="is_published">
                                        { dataFormatter.booleanFormatter(item.is_published) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.gradebooks_owner_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Gradebook_entries Student</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Score</th>
                                
                                
                                
                                <th>EntryStatus</th>
                                
                                
                                
                                <th>RecordedAt</th>
                                
                                
                                
                                
                                
                                <th>Remarks</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.gradebook_entries_student && Array.isArray(users.gradebook_entries_student) &&
                              users.gradebook_entries_student.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/gradebook_entries/gradebook_entries-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="score">
                                        { item.score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entry_status">
                                        { item.entry_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="recorded_at">
                                        { dataFormatter.dateTimeFormatter(item.recorded_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="remarks">
                                        { item.remarks }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.gradebook_entries_student?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                <>
                    <p className={'block font-bold mb-2'}>Gradebook_entries RecordedBy</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Score</th>
                                
                                
                                
                                <th>EntryStatus</th>
                                
                                
                                
                                <th>RecordedAt</th>
                                
                                
                                
                                
                                
                                <th>Remarks</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.gradebook_entries_recorded_by && Array.isArray(users.gradebook_entries_recorded_by) &&
                              users.gradebook_entries_recorded_by.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/gradebook_entries/gradebook_entries-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="score">
                                        { item.score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="entry_status">
                                        { item.entry_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="recorded_at">
                                        { dataFormatter.dateTimeFormatter(item.recorded_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="remarks">
                                        { item.remarks }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.gradebook_entries_recorded_by?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Adviser_reports AdviserTeacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>ReportStatus</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.adviser_reports_adviser_teacher && Array.isArray(users.adviser_reports_adviser_teacher) &&
                              users.adviser_reports_adviser_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/adviser_reports/adviser_reports-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="report_status">
                                        { item.report_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.adviser_reports_adviser_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                <>
                    <p className={'block font-bold mb-2'}>Adviser_reports SubmittedByTeacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>ReportStatus</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.adviser_reports_submitted_by_teacher && Array.isArray(users.adviser_reports_submitted_by_teacher) &&
                              users.adviser_reports_submitted_by_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/adviser_reports/adviser_reports-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="report_status">
                                        { item.report_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.adviser_reports_submitted_by_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Announcements PostedBy</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>AnnouncementTitle</th>
                                
                                
                                
                                
                                
                                <th>AudienceType</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>TargetRole</th>
                                
                                
                                
                                
                                
                                <th>PostedAt</th>
                                
                                
                                
                                <th>ExpiresAt</th>
                                
                                
                                
                                <th>Pinned</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.announcements_posted_by && Array.isArray(users.announcements_posted_by) &&
                              users.announcements_posted_by.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/announcements/announcements-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="announcement_title">
                                        { item.announcement_title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="audience_type">
                                        { item.audience_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="target_role">
                                        { item.target_role }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="posted_at">
                                        { dataFormatter.dateTimeFormatter(item.posted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expires_at">
                                        { dataFormatter.dateTimeFormatter(item.expires_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="pinned">
                                        { dataFormatter.booleanFormatter(item.pinned) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.announcements_posted_by?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Notifications Recipient</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>NotificationType</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>Message</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>IsRead</th>
                                
                                
                                
                                <th>ReadAt</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>Priority</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.notifications_recipient && Array.isArray(users.notifications_recipient) &&
                              users.notifications_recipient.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/notifications/notifications-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="notification_type">
                                        { item.notification_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="message">
                                        { item.message }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_read">
                                        { dataFormatter.booleanFormatter(item.is_read) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="read_at">
                                        { dataFormatter.dateTimeFormatter(item.read_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="priority">
                                        { item.priority }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.notifications_recipient?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                <>
                    <p className={'block font-bold mb-2'}>Notifications SentBy</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>NotificationType</th>
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>Message</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>IsRead</th>
                                
                                
                                
                                <th>ReadAt</th>
                                
                                
                                
                                <th>SentAt</th>
                                
                                
                                
                                <th>Priority</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.notifications_sent_by && Array.isArray(users.notifications_sent_by) &&
                              users.notifications_sent_by.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/notifications/notifications-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="notification_type">
                                        { item.notification_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="message">
                                        { item.message }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_read">
                                        { dataFormatter.booleanFormatter(item.is_read) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="read_at">
                                        { dataFormatter.dateTimeFormatter(item.read_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="sent_at">
                                        { dataFormatter.dateTimeFormatter(item.sent_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="priority">
                                        { item.priority }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.notifications_sent_by?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Account_applications Applicant</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RequestedRole</th>
                                
                                
                                
                                <th>ApplicationStatus</th>
                                
                                
                                
                                <th>ApplicationNotes</th>
                                
                                
                                
                                
                                
                                <th>ReviewedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.account_applications_applicant && Array.isArray(users.account_applications_applicant) &&
                              users.account_applications_applicant.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/account_applications/account_applications-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="requested_role">
                                        { item.requested_role }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="application_status">
                                        { item.application_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="application_notes">
                                        { item.application_notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reviewed_at">
                                        { dataFormatter.dateTimeFormatter(item.reviewed_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.account_applications_applicant?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                <>
                    <p className={'block font-bold mb-2'}>Account_applications ReviewedBy</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>RequestedRole</th>
                                
                                
                                
                                <th>ApplicationStatus</th>
                                
                                
                                
                                <th>ApplicationNotes</th>
                                
                                
                                
                                
                                
                                <th>ReviewedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.account_applications_reviewed_by && Array.isArray(users.account_applications_reviewed_by) &&
                              users.account_applications_reviewed_by.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/account_applications/account_applications-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="requested_role">
                                        { item.requested_role }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="application_status">
                                        { item.application_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="application_notes">
                                        { item.application_notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reviewed_at">
                                        { dataFormatter.dateTimeFormatter(item.reviewed_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.account_applications_reviewed_by?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Security_events User</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>EventType</th>
                                
                                
                                
                                <th>EventAt</th>
                                
                                
                                
                                <th>IPAddress</th>
                                
                                
                                
                                <th>UserAgent</th>
                                
                                
                                
                                <th>RiskLevel</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.security_events_user && Array.isArray(users.security_events_user) &&
                              users.security_events_user.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/security_events/security_events-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="event_type">
                                        { item.event_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="event_at">
                                        { dataFormatter.dateTimeFormatter(item.event_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ip_address">
                                        { item.ip_address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="user_agent">
                                        { item.user_agent }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="risk_level">
                                        { item.risk_level }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.security_events_user?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Feedback_items SubmittedBy</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Rating</th>
                                
                                
                                
                                <th>FeedbackType</th>
                                
                                
                                
                                <th>FeedbackTitle</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {users.feedback_items_submitted_by && Array.isArray(users.feedback_items_submitted_by) &&
                              users.feedback_items_submitted_by.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/feedback_items/feedback_items-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="rating">
                                        { item.rating }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="feedback_type">
                                        { item.feedback_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="feedback_title">
                                        { item.feedback_title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!users?.feedback_items_submitted_by?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                

                <BaseDivider />

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

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

export default UsersView;