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/weather_states/weather_statesSlice'
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 Weather_statesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { weather_states } = useAppSelector((state) => state.weather_states)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>WeatherType</p>
                    <p>{weather_states?.weather_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>TemperatureC</p>
                  <p>{weather_states?.temperature_c || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>WindSpeed</p>
                  <p>{weather_states?.wind_speed || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>RainIntensity</p>
                  <p>{weather_states?.rain_intensity || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='HasThunder'>
                    <SwitchField
                      field={{name: 'has_thunder', value: weather_states?.has_thunder}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>World_calendar_days WeatherState</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>DayStartAt</th>
                                
                                
                                
                                <th>DayEndAt</th>
                                
                                
                                
                                <th>Season</th>
                                
                                
                                
                                
                                
                                <th>TourismIndex</th>
                                
                                
                                
                                <th>InflationIndex</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {weather_states.world_calendar_days_weather_state && Array.isArray(weather_states.world_calendar_days_weather_state) &&
                              weather_states.world_calendar_days_weather_state.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/world_calendar_days/world_calendar_days-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="day_start_at">
                                        { dataFormatter.dateTimeFormatter(item.day_start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="day_end_at">
                                        { dataFormatter.dateTimeFormatter(item.day_end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="season">
                                        { item.season }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="tourism_index">
                                        { item.tourism_index }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="inflation_index">
                                        { item.inflation_index }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!weather_states?.world_calendar_days_weather_state?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Weather_statesView;