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/end_of_summer_trip_options/end_of_summer_trip_optionsSlice'
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 End_of_summer_trip_optionsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { end_of_summer_trip_options } = useAppSelector((state) => state.end_of_summer_trip_options)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>OptionType</p>
                    <p>{end_of_summer_trip_options?.option_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Destination</p>
                    <p>{end_of_summer_trip_options?.destination}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>CampSession</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{end_of_summer_trip_options?.camp_session?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>EstimatedPrice</p>
                  <p>{end_of_summer_trip_options?.estimated_price || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='Active'>
                    <SwitchField
                      field={{name: 'is_active', value: end_of_summer_trip_options?.is_active}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>End_of_summer_trip_selections TripOption</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>SelectionStatus</th>
                                
                                
                                
                                <th>SelectedAt</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {end_of_summer_trip_options.end_of_summer_trip_selections_trip_option && Array.isArray(end_of_summer_trip_options.end_of_summer_trip_selections_trip_option) &&
                              end_of_summer_trip_options.end_of_summer_trip_selections_trip_option.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/end_of_summer_trip_selections/end_of_summer_trip_selections-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="selected_datetime">
                                        { dataFormatter.dateTimeFormatter(item.selected_datetime) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!end_of_summer_trip_options?.end_of_summer_trip_selections_trip_option?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                

                <BaseDivider />

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

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

export default End_of_summer_trip_optionsView;