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/nursing_staff/nursing_staffSlice'
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 Nursing_staffView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { nursing_staff } = useAppSelector((state) => state.nursing_staff)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>اسمالممرض/ة</p>
                    <p>{nursing_staff?.full_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>الرقمالوطني</p>
                    <p>{nursing_staff?.national_number}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>التخصص</p>
                    <p>{nursing_staff?.specialty}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>العنوان</p>
                    <p>{nursing_staff?.address}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>الهاتف</p>
                    <p>{nursing_staff?.phone}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>الحالةالاجتماعية</p>
                    <p>{nursing_staff?.marital_status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>عددالأولاد</p>
                  <p>{nursing_staff?.children_count || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='مناوباتليلية'>
                    <SwitchField
                      field={{name: 'night_shifts', value: nursing_staff?.night_shifts}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>الراتب</p>
                  <p>{nursing_staff?.salary || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>مكافآت</p>
                  <p>{nursing_staff?.bonuses || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              
                <FormField label='تاريخالتوظيف'>
                    {nursing_staff.hire_date ? <DatePicker
                      dateFormat="yyyy-MM-dd hh:mm"
                      showTimeSelect
                      selected={nursing_staff.hire_date ?
                        new Date(
                          dayjs(nursing_staff.hire_date).format('YYYY-MM-DD hh:mm'),
                        ) : null
                      }
                      disabled
                    /> : <p>No تاريخالتوظيف</p>}
                </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>
                            {nursing_staff.room_bookings_supervising_nurse && Array.isArray(nursing_staff.room_bookings_supervising_nurse) &&
                              nursing_staff.room_bookings_supervising_nurse.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>
                        {!nursing_staff?.room_bookings_supervising_nurse?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Nursing_staffView;