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/unit_types/unit_typesSlice'
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";

import {hasPermission} from "../../helpers/userPermissions";


const Unit_typesView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { unit_types } = useAppSelector((state) => state.unit_types)
    
    const { currentUser } = useAppSelector((state) => state.auth);
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Property</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{unit_types?.property?.name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Code</p>
                    <p>{unit_types?.code}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Maxoccupancy</p>
                  <p>{unit_types?.max_occupancy || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Bedrooms</p>
                  <p>{unit_types?.bedrooms || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Bathrooms</p>
                  <p>{unit_types?.bathrooms || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Size(sqm)</p>
                  <p>{unit_types?.size_sqm || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

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

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Basenightlyrate</p>
                  <p>{unit_types?.base_nightly_rate || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Basemonthlyrate</p>
                  <p>{unit_types?.base_monthly_rate || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>Minimumstay(nights)</p>
                  <p>{unit_types?.minimum_stay_nights || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              

              
                <>
                    <p className={'block font-bold mb-2'}>Units</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                    <th>Unitnumber</th>
                                
                                
                                
                                    <th>Floor</th>
                                
                                
                                
                                    <th>Status</th>
                                
                                
                                
                                    <th>Maxoccupancyoverride</th>
                                
                                
                                
                                    <th>Notes</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {unit_types.units && Array.isArray(unit_types.units) &&
                              unit_types.units.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/units/units-view/?id=${item.id}`)}>
                                  
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                  
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="unit_number">
                                        { item.unit_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="floor">
                                        { item.floor }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_occupancy_override">
                                        { item.max_occupancy_override }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!unit_types?.units?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
              

              

              
              

              

              

              

              

              

              

              

              

              

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

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Units Unittype</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>Unitnumber</th>
                                
                                
                                
                                <th>Floor</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Maxoccupancyoverride</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {unit_types.units_unit_type && Array.isArray(unit_types.units_unit_type) &&
                              unit_types.units_unit_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/units/units-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="unit_number">
                                        { item.unit_number }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="floor">
                                        { item.floor }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_occupancy_override">
                                        { item.max_occupancy_override }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!unit_types?.units_unit_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Negotiated_rates Unittype</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Ratetype</th>
                                
                                
                                
                                <th>Rateamount</th>
                                
                                
                                
                                <th>Validfrom</th>
                                
                                
                                
                                <th>Validuntil</th>
                                
                                
                                
                                <th>Minimumstay(nights)</th>
                                
                                
                                
                                <th>Isactive</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {unit_types.negotiated_rates_unit_type && Array.isArray(unit_types.negotiated_rates_unit_type) &&
                              unit_types.negotiated_rates_unit_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/negotiated_rates/negotiated_rates-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="rate_type">
                                        { item.rate_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="rate_amount">
                                        { item.rate_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="valid_from">
                                        { dataFormatter.dateTimeFormatter(item.valid_from) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="valid_until">
                                        { dataFormatter.dateTimeFormatter(item.valid_until) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="minimum_stay_nights">
                                        { item.minimum_stay_nights }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_active">
                                        { dataFormatter.booleanFormatter(item.is_active) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!unit_types?.negotiated_rates_unit_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Booking_requests Preferredunittype</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Requestcode</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>Check-inat</th>
                                
                                
                                
                                <th>Check-outat</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>Preferredbedrooms</th>
                                
                                
                                
                                <th>Guestcount</th>
                                
                                
                                
                                <th>Purposeofstay</th>
                                
                                
                                
                                <th>Specialrequirements</th>
                                
                                
                                
                                <th>Budgetcode</th>
                                
                                
                                
                                <th>Maxbudgetamount</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {unit_types.booking_requests_preferred_unit_type && Array.isArray(unit_types.booking_requests_preferred_unit_type) &&
                              unit_types.booking_requests_preferred_unit_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/booking_requests/booking_requests-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="request_code">
                                        { item.request_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </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="preferred_bedrooms">
                                        { item.preferred_bedrooms }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="guest_count">
                                        { item.guest_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="purpose_of_stay">
                                        { item.purpose_of_stay }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="special_requirements">
                                        { item.special_requirements }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="budget_code">
                                        { item.budget_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="max_budget_amount">
                                        { item.max_budget_amount }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!unit_types?.booking_requests_preferred_unit_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Reservations Unittype</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Reservationcode</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>Check-inat</th>
                                
                                
                                
                                <th>Check-outat</th>
                                
                                
                                
                                <th>Actualcheck-inat</th>
                                
                                
                                
                                <th>Actualcheck-outat</th>
                                
                                
                                
                                <th>Earlycheck-in</th>
                                
                                
                                
                                <th>Latecheck-out</th>
                                
                                
                                
                                <th>Guestcount</th>
                                
                                
                                
                                <th>Nightlyrate</th>
                                
                                
                                
                                <th>Monthlyrate</th>
                                
                                
                                
                                <th>Currency</th>
                                
                                
                                
                                <th>Internalnotes</th>
                                
                                
                                
                                <th>Externalnotes</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {unit_types.reservations_unit_type && Array.isArray(unit_types.reservations_unit_type) &&
                              unit_types.reservations_unit_type.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/reservations/reservations-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="reservation_code">
                                        { item.reservation_code }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </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="actual_check_in_at">
                                        { dataFormatter.dateTimeFormatter(item.actual_check_in_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="actual_check_out_at">
                                        { dataFormatter.dateTimeFormatter(item.actual_check_out_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="early_check_in">
                                        { dataFormatter.booleanFormatter(item.early_check_in) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="late_check_out">
                                        { dataFormatter.booleanFormatter(item.late_check_out) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="guest_count">
                                        { item.guest_count }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="nightly_rate">
                                        { item.nightly_rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="monthly_rate">
                                        { item.monthly_rate }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="currency">
                                        { item.currency }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="internal_notes">
                                        { item.internal_notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="external_notes">
                                        { item.external_notes }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!unit_types?.reservations_unit_type?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Unit_typesView;