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/campuses/campusesSlice'
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 CampusesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { campuses } = useAppSelector((state) => state.campuses)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>AddressLine1</p>
                    <p>{campuses?.address_line1}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>City</p>
                    <p>{campuses?.city}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>State</p>
                    <p>{campuses?.state}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>PostalCode</p>
                    <p>{campuses?.postal_code}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Camp_sessions Campus</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>SessionName</th>
                                
                                
                                
                                <th>ThemeTitle</th>
                                
                                
                                
                                
                                
                                <th>ThemeScriptureReference</th>
                                
                                
                                
                                
                                
                                <th>StartDate</th>
                                
                                
                                
                                <th>EndDate</th>
                                
                                
                                
                                <th>DayCampHours</th>
                                
                                
                                
                                <th>ThirdShiftHours</th>
                                
                                
                                
                                
                                
                                <th>Published</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {campuses.camp_sessions_campus && Array.isArray(campuses.camp_sessions_campus) &&
                              campuses.camp_sessions_campus.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/camp_sessions/camp_sessions-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="theme_title">
                                        { item.theme_title }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="theme_scripture_reference">
                                        { item.theme_scripture_reference }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="start_datetime">
                                        { dataFormatter.dateTimeFormatter(item.start_datetime) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_datetime">
                                        { dataFormatter.dateTimeFormatter(item.end_datetime) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="day_camp_hours">
                                        { item.day_camp_hours }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="third_shift_hours">
                                        { item.third_shift_hours }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_published">
                                        { dataFormatter.booleanFormatter(item.is_published) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!campuses?.camp_sessions_campus?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default CampusesView;