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/inpatient_rooms/inpatient_roomsSlice'
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 Inpatient_roomsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { inpatient_rooms } = useAppSelector((state) => state.inpatient_rooms)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>رقمالغرفة</p>
                    <p>{inpatient_rooms?.room_number}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>اسمالجناح</p>
                    <p>{inpatient_rooms?.ward_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>نوعالغرفة</p>
                    <p>{inpatient_rooms?.room_type ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>سعراليومالواحد</p>
                  <p>{inpatient_rooms?.price_per_day || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>السعة</p>
                  <p>{inpatient_rooms?.capacity || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='متاحة'>
                    <SwitchField
                      field={{name: 'is_available', value: inpatient_rooms?.is_available}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Room_bookings الغرفة</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>رقمالحجز</th>
                                
                                
                                
                                
                                
                                
                                
                                <th>تاريخالدخول</th>
                                
                                
                                
                                <th>تاريخالخروج</th>
                                
                                
                                
                                <th>عددالأيام</th>
                                
                                
                                
                                <th>سعراليوم</th>
                                
                                
                                
                                <th>السعرالإجمالي</th>
                                
                                
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {inpatient_rooms.room_bookings_room && Array.isArray(inpatient_rooms.room_bookings_room) &&
                              inpatient_rooms.room_bookings_room.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/room_bookings/room_bookings-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="booking_number">
                                        { item.booking_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="admission_date">
                                        { dataFormatter.dateTimeFormatter(item.admission_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="discharge_date">
                                        { dataFormatter.dateTimeFormatter(item.discharge_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="days">
                                        { item.days }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="price_per_day">
                                        { item.price_per_day }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="total_price">
                                        { item.total_price }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!inpatient_rooms?.room_bookings_room?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Inpatient_roomsView;