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/age_groups/age_groupsSlice'
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 Age_groupsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { age_groups } = useAppSelector((state) => state.age_groups)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>MinimumGrade</p>
                  <p>{age_groups?.min_grade || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>MaximumGrade</p>
                  <p>{age_groups?.max_grade || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ThemeScriptureReference</p>
                    <p>{age_groups?.theme_scripture_reference}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Enrollments AgeGroup</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>SubmittedAt</th>
                                
                                
                                
                                <th>EnrollmentStatus</th>
                                
                                
                                
                                <th>ApplicationFeeWaived</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {age_groups.enrollments_age_group && Array.isArray(age_groups.enrollments_age_group) &&
                              age_groups.enrollments_age_group.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/enrollments/enrollments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="submitted_datetime">
                                        { dataFormatter.dateTimeFormatter(item.submitted_datetime) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="application_fee_waived">
                                        { dataFormatter.booleanFormatter(item.application_fee_waived) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!age_groups?.enrollments_age_group?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Field_trip_events AgeGroup</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>DepartTime</th>
                                
                                
                                
                                <th>ReturnTime</th>
                                
                                
                                
                                <th>PricePerStudent</th>
                                
                                
                                
                                <th>Capacity</th>
                                
                                
                                
                                <th>EventStatus</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {age_groups.field_trip_events_age_group && Array.isArray(age_groups.field_trip_events_age_group) &&
                              age_groups.field_trip_events_age_group.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/field_trip_events/field_trip_events-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="depart_datetime">
                                        { dataFormatter.dateTimeFormatter(item.depart_datetime) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="return_datetime">
                                        { dataFormatter.dateTimeFormatter(item.return_datetime) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="price_per_student">
                                        { item.price_per_student }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="capacity">
                                        { item.capacity }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!age_groups?.field_trip_events_age_group?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Activity_blocks AgeGroup</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>BlockName</th>
                                
                                
                                
                                <th>ProgramShift</th>
                                
                                
                                
                                <th>BlockStart</th>
                                
                                
                                
                                <th>BlockEnd</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>BlockType</th>
                                
                                
                                
                                <th>Details</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {age_groups.activity_blocks_age_group && Array.isArray(age_groups.activity_blocks_age_group) &&
                              age_groups.activity_blocks_age_group.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/activity_blocks/activity_blocks-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="program_shift">
                                        { item.program_shift }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="block_start_datetime">
                                        { dataFormatter.dateTimeFormatter(item.block_start_datetime) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="block_end_datetime">
                                        { dataFormatter.dateTimeFormatter(item.block_end_datetime) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="block_type">
                                        { item.block_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="details">
                                        { item.details }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!age_groups?.activity_blocks_age_group?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Staff_assignments AgeGroup</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>AssignmentRole</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {age_groups.staff_assignments_age_group && Array.isArray(age_groups.staff_assignments_age_group) &&
                              age_groups.staff_assignments_age_group.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/staff_assignments/staff_assignments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="assignment_role">
                                        { item.assignment_role }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!age_groups?.staff_assignments_age_group?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                

                <BaseDivider />

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

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

export default Age_groupsView;