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/place_categories/place_categoriesSlice'
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 Place_categoriesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { place_categories } = useAppSelector((state) => state.place_categories)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Slug</p>
                    <p>{place_categories?.slug}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>ColorHex</p>
                    <p>{place_categories?.color_hex}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>IconName</p>
                    <p>{place_categories?.icon_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

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

              

              

              

              
              

                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Places Category</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>PlaceName</th>
                                
                                
                                
                                
                                
                                <th>ShortDescription</th>
                                
                                
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>City</th>
                                
                                
                                
                                <th>Province</th>
                                
                                
                                
                                <th>PostalCode</th>
                                
                                
                                
                                <th>Latitude</th>
                                
                                
                                
                                <th>Longitude</th>
                                
                                
                                
                                <th>PhoneNumber</th>
                                
                                
                                
                                <th>WhatsAppNumber</th>
                                
                                
                                
                                <th>Email</th>
                                
                                
                                
                                <th>WebsiteURL</th>
                                
                                
                                
                                <th>GoogleMapsURL</th>
                                
                                
                                
                                
                                
                                <th>PriceLevel</th>
                                
                                
                                
                                <th>AveragePrice</th>
                                
                                
                                
                                <th>RatingAverage</th>
                                
                                
                                
                                <th>RatingCount</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>IsVerified</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {place_categories.places_category && Array.isArray(place_categories.places_category) &&
                              place_categories.places_category.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/places/places-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="short_description">
                                        { item.short_description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="city">
                                        { item.city }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="province">
                                        { item.province }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="postal_code">
                                        { item.postal_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="latitude">
                                        { item.latitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="longitude">
                                        { item.longitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="phone_number">
                                        { item.phone_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="whatsapp_number">
                                        { item.whatsapp_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="email">
                                        { item.email }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="website_url">
                                        { item.website_url }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="google_maps_url">
                                        { item.google_maps_url }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="price_level">
                                        { item.price_level }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="average_price">
                                        { item.average_price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rating_average">
                                        { item.rating_average }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rating_count">
                                        { item.rating_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_verified">
                                        { dataFormatter.booleanFormatter(item.is_verified) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!place_categories?.places_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Search_logs Category</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>QueryText</th>
                                
                                
                                
                                
                                
                                <th>SearchLatitude</th>
                                
                                
                                
                                <th>SearchLongitude</th>
                                
                                
                                
                                <th>RadiusKm</th>
                                
                                
                                
                                <th>SearchedAt</th>
                                
                                
                                
                                <th>ResultsCount</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {place_categories.search_logs_category && Array.isArray(place_categories.search_logs_category) &&
                              place_categories.search_logs_category.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/search_logs/search_logs-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="query_text">
                                        { item.query_text }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="search_latitude">
                                        { item.search_latitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="search_longitude">
                                        { item.search_longitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="radius_km">
                                        { item.radius_km }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="searched_at">
                                        { dataFormatter.dateTimeFormatter(item.searched_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="results_count">
                                        { item.results_count }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!place_categories?.search_logs_category?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                

                <BaseDivider />

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

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

export default Place_categoriesView;