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/field_trip_catalog/field_trip_catalogSlice'
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 Field_trip_catalogView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { field_trip_catalog } = useAppSelector((state) => state.field_trip_catalog)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Category</p>
                    <p>{field_trip_catalog?.category ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Location</p>
                    <p>{field_trip_catalog?.location_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>GradeRange</p>
                    <p>{field_trip_catalog?.grade_range}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>TypicalMinRate</p>
                  <p>{field_trip_catalog?.typical_min_rate || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>TypicalMaxRate</p>
                  <p>{field_trip_catalog?.typical_max_rate || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='SeparatePaymentRequired'>
                    <SwitchField
                      field={{name: 'separate_payment_required', value: field_trip_catalog?.separate_payment_required}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Field_trip_events FieldTrip</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>
                            {field_trip_catalog.field_trip_events_field_trip && Array.isArray(field_trip_catalog.field_trip_events_field_trip) &&
                              field_trip_catalog.field_trip_events_field_trip.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>
                        {!field_trip_catalog?.field_trip_events_field_trip?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Field_trip_catalogView;