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/staff_members/staff_membersSlice'
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";


const Staff_membersView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { staff_members } = useAppSelector((state) => state.staff_members)
    

    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 staff_members')}</title>
          </Head>
          <SectionMain>
            <SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View staff_members')} main>
                <BaseButton
                  color='info'
                  label='Edit'
                  href={`/staff_members/staff_members-edit/?id=${id}`}
                />
            </SectionTitleLineWithButton>
            <CardBox>
            

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>User</p>
                    
                    
                        <p>{staff_members?.user?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>FullName</p>
                    <p>{staff_members?.full_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>StaffRole</p>
                    <p>{staff_members?.staff_role ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Bio</p>
                  {staff_members.bio
                    ? <p dangerouslySetInnerHTML={{__html: staff_members.bio}}/>
                    : <p>No data</p>
                  }
                </div>
              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

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

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PhoneNumber</p>
                    <p>{staff_members?.phone_number}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>SubjectsTaught</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                    <th>SubjectNameAfaanOromoo</th>
                                
                                
                                
                                    <th>SubjectNameAmharic</th>
                                
                                
                                
                                    <th>SubjectNameEnglish</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                    <th>TextbookReferences</th>
                                
                                
                                
                                    <th>Active</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.subjects_taught && Array.isArray(staff_members.subjects_taught) &&
                              staff_members.subjects_taught.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/subjects/subjects-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                  
                                    
                                    <td data-label="name_om">
                                        { item.name_om }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name_am">
                                        { item.name_am }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name_en">
                                        { item.name_en }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="textbook_references">
                                        { item.textbook_references }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="active">
                                        { dataFormatter.booleanFormatter(item.active) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.subjects_taught?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Subject_offerings ResponsibleTeacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>TopicsOutline</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.subject_offerings_responsible_teacher && Array.isArray(staff_members.subject_offerings_responsible_teacher) &&
                              staff_members.subject_offerings_responsible_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/subject_offerings/subject_offerings-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="topics_outline">
                                        { item.topics_outline }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.subject_offerings_responsible_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Class_sections HomeroomTeacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>SectionName</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Capacity</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.class_sections_homeroom_teacher && Array.isArray(staff_members.class_sections_homeroom_teacher) &&
                              staff_members.class_sections_homeroom_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/class_sections/class_sections-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="capacity">
                                        { item.capacity }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.class_sections_homeroom_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>News_posts Author</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>TitleAfaanOromoo</th>
                                
                                
                                
                                <th>TitleAmharic</th>
                                
                                
                                
                                <th>TitleEnglish</th>
                                
                                
                                
                                <th>ExcerptAfaanOromoo</th>
                                
                                
                                
                                <th>ExcerptAmharic</th>
                                
                                
                                
                                <th>ExcerptEnglish</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>PublishedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.news_posts_author && Array.isArray(staff_members.news_posts_author) &&
                              staff_members.news_posts_author.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/news_posts/news_posts-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="title_om">
                                        { item.title_om }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title_am">
                                        { item.title_am }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title_en">
                                        { item.title_en }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="excerpt_om">
                                        { item.excerpt_om }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="excerpt_am">
                                        { item.excerpt_am }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="excerpt_en">
                                        { item.excerpt_en }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="published_at">
                                        { dataFormatter.dateTimeFormatter(item.published_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.news_posts_author?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Study_materials UploadedBy</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>TitleAfaanOromoo</th>
                                
                                
                                
                                <th>TitleAmharic</th>
                                
                                
                                
                                <th>TitleEnglish</th>
                                
                                
                                
                                <th>MaterialType</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ExternalURL</th>
                                
                                
                                
                                <th>Visibility</th>
                                
                                
                                
                                
                                
                                <th>PublishedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.study_materials_uploaded_by && Array.isArray(staff_members.study_materials_uploaded_by) &&
                              staff_members.study_materials_uploaded_by.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/study_materials/study_materials-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="title_om">
                                        { item.title_om }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title_am">
                                        { item.title_am }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="title_en">
                                        { item.title_en }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="material_type">
                                        { item.material_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="external_url">
                                        { item.external_url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="visibility">
                                        { item.visibility }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="published_at">
                                        { dataFormatter.dateTimeFormatter(item.published_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.study_materials_uploaded_by?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Exam_results EnteredBy</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>OutOf</th>
                                
                                
                                
                                <th>ResultStatus</th>
                                
                                
                                
                                
                                
                                <th>EnteredAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.exam_results_entered_by && Array.isArray(staff_members.exam_results_entered_by) &&
                              staff_members.exam_results_entered_by.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/exam_results/exam_results-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="score">
                                        { item.score }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="out_of">
                                        { item.out_of }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="result_status">
                                        { item.result_status }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="entered_at">
                                        { dataFormatter.dateTimeFormatter(item.entered_at) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.exam_results_entered_by?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Attendance_sessions Teacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>SessionAt</th>
                                
                                
                                
                                <th>SessionType</th>
                                
                                
                                
                                <th>Note</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.attendance_sessions_teacher && Array.isArray(staff_members.attendance_sessions_teacher) &&
                              staff_members.attendance_sessions_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/attendance_sessions/attendance_sessions-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="session_at">
                                        { dataFormatter.dateTimeFormatter(item.session_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="session_type">
                                        { item.session_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="note">
                                        { item.note }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.attendance_sessions_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Class_schedules Teacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Weekday</th>
                                
                                
                                
                                <th>PeriodLabel</th>
                                
                                
                                
                                <th>StartsAt</th>
                                
                                
                                
                                <th>EndsAt</th>
                                
                                
                                
                                <th>Room</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.class_schedules_teacher && Array.isArray(staff_members.class_schedules_teacher) &&
                              staff_members.class_schedules_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/class_schedules/class_schedules-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="weekday">
                                        { item.weekday }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="period_label">
                                        { item.period_label }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="starts_at">
                                        { dataFormatter.dateTimeFormatter(item.starts_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="ends_at">
                                        { dataFormatter.dateTimeFormatter(item.ends_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="room">
                                        { item.room }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.class_schedules_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Assignments Teacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>AssignedAt</th>
                                
                                
                                
                                <th>DueAt</th>
                                
                                
                                
                                <th>Visibility</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.assignments_teacher && Array.isArray(staff_members.assignments_teacher) &&
                              staff_members.assignments_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/assignments/assignments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="assigned_at">
                                        { dataFormatter.dateTimeFormatter(item.assigned_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_at">
                                        { dataFormatter.dateTimeFormatter(item.due_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="visibility">
                                        { item.visibility }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.assignments_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Lesson_plans Teacher</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>WeekStartAt</th>
                                
                                
                                
                                <th>WeekEndAt</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {staff_members.lesson_plans_teacher && Array.isArray(staff_members.lesson_plans_teacher) &&
                              staff_members.lesson_plans_teacher.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/lesson_plans/lesson_plans-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="week_start_at">
                                        { dataFormatter.dateTimeFormatter(item.week_start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="week_end_at">
                                        { dataFormatter.dateTimeFormatter(item.week_end_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!staff_members?.lesson_plans_teacher?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Staff_membersView;