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/grade_levels/grade_levelsSlice'
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 Grade_levelsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { grade_levels } = useAppSelector((state) => state.grade_levels)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>GradeLevel</p>
                    <p>{grade_levels?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SortOrder</p>
                  <p>{grade_levels?.sort_order || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              
                <FormField label='Multi Text' hasTextareaHeight>
                  <textarea className={'w-full'} disabled value={grade_levels?.description} />
                </FormField>
              

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Textbooks GradeLevel</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>Publisher</th>
                                
                                
                                
                                <th>Edition</th>
                                
                                
                                
                                <th>ISBN</th>
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {grade_levels.textbooks_grade_level && Array.isArray(grade_levels.textbooks_grade_level) &&
                              grade_levels.textbooks_grade_level.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/textbooks/textbooks-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="publisher">
                                        { item.publisher }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="edition">
                                        { item.edition }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="isbn">
                                        { item.isbn }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!grade_levels?.textbooks_grade_level?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Curriculum_standards GradeLevel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>StandardCode</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>CompetencyArea</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {grade_levels.curriculum_standards_grade_level && Array.isArray(grade_levels.curriculum_standards_grade_level) &&
                              grade_levels.curriculum_standards_grade_level.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/curriculum_standards/curriculum_standards-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="competency_area">
                                        { item.competency_area }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!grade_levels?.curriculum_standards_grade_level?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Question_banks GradeLevel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>BankName</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>IsPublic</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {grade_levels.question_banks_grade_level && Array.isArray(grade_levels.question_banks_grade_level) &&
                              grade_levels.question_banks_grade_level.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/question_banks/question_banks-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_public">
                                        { dataFormatter.booleanFormatter(item.is_public) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!grade_levels?.question_banks_grade_level?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Tests GradeLevel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>TestTitle</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>BuildMode</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>TargetQuestionCount</th>
                                
                                
                                
                                <th>TargetTotalPoints</th>
                                
                                
                                
                                <th>TargetAverageDifficulty</th>
                                
                                
                                
                                <th>ShuffleQuestions</th>
                                
                                
                                
                                <th>ShuffleAnswers</th>
                                
                                
                                
                                <th>AssignedAt</th>
                                
                                
                                
                                <th>DueAt</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {grade_levels.tests_grade_level && Array.isArray(grade_levels.tests_grade_level) &&
                              grade_levels.tests_grade_level.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/tests/tests-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="build_mode">
                                        { item.build_mode }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="target_question_count">
                                        { item.target_question_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="target_total_points">
                                        { item.target_total_points }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="target_average_difficulty">
                                        { item.target_average_difficulty }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="shuffle_questions">
                                        { dataFormatter.booleanFormatter(item.shuffle_questions) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="shuffle_answers">
                                        { dataFormatter.booleanFormatter(item.shuffle_answers) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="assigned_at">
                                        { dataFormatter.dateTimeFormatter(item.assigned_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="due_at">
                                        { dataFormatter.dateTimeFormatter(item.due_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!grade_levels?.tests_grade_level?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Grade_levelsView;