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/streams/streamsSlice'
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 StreamsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { streams } = useAppSelector((state) => state.streams)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>StreamNameAfaanOromoo</p>
                    <p>{streams?.name_om}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>StreamNameAmharic</p>
                    <p>{streams?.name_am}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>StreamNameEnglish</p>
                    <p>{streams?.name_en}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>StreamType</p>
                    <p>{streams?.stream_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Subject_offerings Stream</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>
                            {streams.subject_offerings_stream && Array.isArray(streams.subject_offerings_stream) &&
                              streams.subject_offerings_stream.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>
                        {!streams?.subject_offerings_stream?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Students CurrentStream</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>FullName</th>
                                
                                
                                
                                <th>StudentCode</th>
                                
                                
                                
                                <th>Gender</th>
                                
                                
                                
                                <th>DateOfBirth</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>GuardianName</th>
                                
                                
                                
                                <th>GuardianPhone</th>
                                
                                
                                
                                <th>AddressText</th>
                                
                                
                                
                                <th>Active</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {streams.students_current_stream && Array.isArray(streams.students_current_stream) &&
                              streams.students_current_stream.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/students/students-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="full_name">
                                        { item.full_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="student_code">
                                        { item.student_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gender">
                                        { item.gender }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="date_of_birth">
                                        { dataFormatter.dateTimeFormatter(item.date_of_birth) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="guardian_name">
                                        { item.guardian_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="guardian_phone">
                                        { item.guardian_phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_text">
                                        { item.address_text }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="active">
                                        { dataFormatter.booleanFormatter(item.active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!streams?.students_current_stream?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Class_sections Stream</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>
                            {streams.class_sections_stream && Array.isArray(streams.class_sections_stream) &&
                              streams.class_sections_stream.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>
                        {!streams?.class_sections_stream?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Study_materials Stream</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>
                            {streams.study_materials_stream && Array.isArray(streams.study_materials_stream) &&
                              streams.study_materials_stream.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>
                        {!streams?.study_materials_stream?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Exams Stream</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>ExamName</th>
                                
                                
                                
                                <th>ExamType</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>StartsAt</th>
                                
                                
                                
                                <th>EndsAt</th>
                                
                                
                                
                                <th>PublicResults</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {streams.exams_stream && Array.isArray(streams.exams_stream) &&
                              streams.exams_stream.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/exams/exams-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="exam_type">
                                        { item.exam_type }
                                    </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="public_results">
                                        { dataFormatter.booleanFormatter(item.public_results) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!streams?.exams_stream?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Admission_applications RequestedStream</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>EntryType</th>
                                
                                
                                
                                <th>ApplicantFullName</th>
                                
                                
                                
                                <th>Gender</th>
                                
                                
                                
                                <th>DateOfBirth</th>
                                
                                
                                
                                <th>PreviousSchool</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>GuardianFullName</th>
                                
                                
                                
                                <th>GuardianPhone</th>
                                
                                
                                
                                <th>GuardianEmail</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {streams.admission_applications_requested_stream && Array.isArray(streams.admission_applications_requested_stream) &&
                              streams.admission_applications_requested_stream.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/admission_applications/admission_applications-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="entry_type">
                                        { item.entry_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="applicant_full_name">
                                        { item.applicant_full_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gender">
                                        { item.gender }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="date_of_birth">
                                        { dataFormatter.dateTimeFormatter(item.date_of_birth) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="previous_school">
                                        { item.previous_school }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="guardian_full_name">
                                        { item.guardian_full_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="guardian_phone">
                                        { item.guardian_phone }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="guardian_email">
                                        { item.guardian_email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address_text">
                                        { item.address_text }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="submitted_at">
                                        { dataFormatter.dateTimeFormatter(item.submitted_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!streams?.admission_applications_requested_stream?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default StreamsView;