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/hotels/hotelsSlice'
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 HotelsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { hotels } = useAppSelector((state) => state.hotels)
    

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

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>LegalName</p>
                    <p>{hotels?.legal_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>TaxNumber</p>
                    <p>{hotels?.tax_number}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Email</p>
                    <p>{hotels?.email}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Phone</p>
                    <p>{hotels?.phone}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Website</p>
                    <p>{hotels?.website}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>AddressLine2</p>
                    <p>{hotels?.address_line2}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Country</p>
                    <p>{hotels?.country}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Timezone</p>
                    <p>{hotels?.timezone}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='Check-inTime'>
                    {hotels.check_in_time ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={hotels.check_in_time ?
                        new Date(
                          dayjs(hotels.check_in_time).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No Check-inTime</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='Check-outTime'>
                    {hotels.check_out_time ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={hotels.check_out_time ?
                        new Date(
                          dayjs(hotels.check_out_time).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No Check-outTime</p>}
                </FormField>
              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>GalleryImages</p>
                    {hotels?.gallery_images?.length
                      ? (
                        <ImageField
                          name={'gallery_images'}
                          image={hotels?.gallery_images}
                          className='w-20 h-20'
                        />
                      ) : <p>No GalleryImages</p>
                    }
                </div>
              

              
              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Description</p>
                  {hotels.description
                    ? <p dangerouslySetInnerHTML={{__html: hotels.description}}/>
                    : <p>No data</p>
                  }
                </div>
              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Room_types Hotel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>RoomTypeName</th>
                                
                                
                                
                                <th>Code</th>
                                
                                
                                
                                <th>ShortDescription</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>MaxOccupancy</th>
                                
                                
                                
                                <th>MaxAdults</th>
                                
                                
                                
                                <th>MaxChildren</th>
                                
                                
                                
                                <th>BedCount</th>
                                
                                
                                
                                <th>BedType</th>
                                
                                
                                
                                <th>BaseArea(sqm)</th>
                                
                                
                                
                                <th>Active</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {hotels.room_types_hotel && Array.isArray(hotels.room_types_hotel) &&
                              hotels.room_types_hotel.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/room_types/room_types-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="short_description">
                                        { item.short_description }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="max_occupancy">
                                        { item.max_occupancy }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_adults">
                                        { item.max_adults }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_children">
                                        { item.max_children }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bed_count">
                                        { item.bed_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="bed_type">
                                        { item.bed_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="base_area_sqm">
                                        { item.base_area_sqm }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!hotels?.room_types_hotel?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Rate_plans Hotel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>RatePlanName</th>
                                
                                
                                
                                <th>Code</th>
                                
                                
                                
                                <th>PricingModel</th>
                                
                                
                                
                                <th>CancellationPolicyType</th>
                                
                                
                                
                                
                                
                                <th>MinStayNights</th>
                                
                                
                                
                                <th>MaxStayNights</th>
                                
                                
                                
                                <th>ReleaseDays</th>
                                
                                
                                
                                <th>BreakfastIncluded</th>
                                
                                
                                
                                <th>Refundable</th>
                                
                                
                                
                                <th>Active</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {hotels.rate_plans_hotel && Array.isArray(hotels.rate_plans_hotel) &&
                              hotels.rate_plans_hotel.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/rate_plans/rate_plans-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="pricing_model">
                                        { item.pricing_model }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cancellation_policy_type">
                                        { item.cancellation_policy_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="min_stay_nights">
                                        { item.min_stay_nights }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_stay_nights">
                                        { item.max_stay_nights }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="release_days">
                                        { item.release_days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_breakfast_included">
                                        { dataFormatter.booleanFormatter(item.is_breakfast_included) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_refundable">
                                        { dataFormatter.booleanFormatter(item.is_refundable) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!hotels?.rate_plans_hotel?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Bookings Hotel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>BookingCode</th>
                                
                                
                                
                                <th>Check-inAt</th>
                                
                                
                                
                                <th>Check-outAt</th>
                                
                                
                                
                                <th>Adults</th>
                                
                                
                                
                                <th>Children</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Source</th>
                                
                                
                                
                                <th>TotalAmount</th>
                                
                                
                                
                                <th>TaxAmount</th>
                                
                                
                                
                                <th>CityTaxAmount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>DepositAmount</th>
                                
                                
                                
                                <th>DepositStatus</th>
                                
                                
                                
                                <th>SpecialRequests</th>
                                
                                
                                
                                <th>CancelledAt</th>
                                
                                
                                
                                <th>CancellationReason</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {hotels.bookings_hotel && Array.isArray(hotels.bookings_hotel) &&
                              hotels.bookings_hotel.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/bookings/bookings-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="booking_code">
                                        { item.booking_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_in_at">
                                        { dataFormatter.dateTimeFormatter(item.check_in_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="check_out_at">
                                        { dataFormatter.dateTimeFormatter(item.check_out_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="adults">
                                        { item.adults }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="children">
                                        { item.children }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="source">
                                        { item.source }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_amount">
                                        { item.total_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tax_amount">
                                        { item.tax_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="city_tax_amount">
                                        { item.city_tax_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deposit_amount">
                                        { item.deposit_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="deposit_status">
                                        { item.deposit_status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="special_requests">
                                        { item.special_requests }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cancelled_at">
                                        { dataFormatter.dateTimeFormatter(item.cancelled_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="cancellation_reason">
                                        { item.cancellation_reason }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!hotels?.bookings_hotel?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Promo_codes Hotel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Code</th>
                                
                                
                                
                                <th>Name</th>
                                
                                
                                
                                <th>DiscountType</th>
                                
                                
                                
                                <th>DiscountValue</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>ValidFromAt</th>
                                
                                
                                
                                <th>ValidToAt</th>
                                
                                
                                
                                <th>MaxUses</th>
                                
                                
                                
                                <th>MaxUsesPerGuest</th>
                                
                                
                                
                                <th>MinNights</th>
                                
                                
                                
                                <th>Active</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {hotels.promo_codes_hotel && Array.isArray(hotels.promo_codes_hotel) &&
                              hotels.promo_codes_hotel.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/promo_codes/promo_codes-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="code">
                                        { item.code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="name">
                                        { item.name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="discount_type">
                                        { item.discount_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="discount_value">
                                        { item.discount_value }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="valid_from_at">
                                        { dataFormatter.dateTimeFormatter(item.valid_from_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="valid_to_at">
                                        { dataFormatter.dateTimeFormatter(item.valid_to_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_uses">
                                        { item.max_uses }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_uses_per_guest">
                                        { item.max_uses_per_guest }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="min_nights">
                                        { item.min_nights }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!hotels?.promo_codes_hotel?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Content_pages Hotel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Title</th>
                                
                                
                                
                                <th>Slug</th>
                                
                                
                                
                                <th>PageType</th>
                                
                                
                                
                                
                                
                                <th>Published</th>
                                
                                
                                
                                <th>PublishedAt</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {hotels.content_pages_hotel && Array.isArray(hotels.content_pages_hotel) &&
                              hotels.content_pages_hotel.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/content_pages/content_pages-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="title">
                                        { item.title }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="slug">
                                        { item.slug }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="page_type">
                                        { item.page_type }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_published">
                                        { dataFormatter.booleanFormatter(item.is_published) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="published_at">
                                        { dataFormatter.dateTimeFormatter(item.published_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!hotels?.content_pages_hotel?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Settings Hotel</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>Key</th>
                                
                                
                                
                                <th>Value</th>
                                
                                
                                
                                <th>ValueType</th>
                                
                                
                                
                                <th>Description</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {hotels.settings_hotel && Array.isArray(hotels.settings_hotel) &&
                              hotels.settings_hotel.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/settings/settings-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="key">
                                        { item.key }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="value">
                                        { item.value }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="value_type">
                                        { item.value_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="description">
                                        { item.description }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!hotels?.settings_hotel?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                

                <BaseDivider />

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

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

export default HotelsView;