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/guarantors/guarantorsSlice'
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 GuarantorsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { guarantors } = useAppSelector((state) => state.guarantors)
    

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

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>اسمالكفيل</p>
                    <p>{guarantors?.name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              

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

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>المريض</p>
                    
                    
                    
                    
                    
                    
                    
                    
                        <p>{guarantors?.patient?.full_name ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Visits الكفيل</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>
                                
                                
                                
                                <th>قياسالسكر</th>
                                
                                
                                
                                <th>النبض</th>
                                
                                
                                
                                <th>درجةالحرارة</th>
                                
                                
                                
                                <th>الأكسجة</th>
                                
                                
                                
                                <th>الشكوىالرئيسية</th>
                                
                                
                                
                                <th>التشخيصالأولي</th>
                                
                                
                                
                                <th>أدويةالإسعاف</th>
                                
                                
                                
                                <th>سوائل/وريدي</th>
                                
                                
                                
                                <th>ملاحظات</th>
                                
                                
                                
                                <th>الحالة</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {guarantors.visits_guarantor && Array.isArray(guarantors.visits_guarantor) &&
                              guarantors.visits_guarantor.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/visits/visits-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="visit_number">
                                        { item.visit_number }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="department">
                                        { item.department }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="visit_price">
                                        { item.visit_price }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="arrival_time">
                                        { dataFormatter.dateTimeFormatter(item.arrival_time) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="discharge_time">
                                        { dataFormatter.dateTimeFormatter(item.discharge_time) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="blood_pressure">
                                        { item.blood_pressure }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="glucose">
                                        { item.glucose }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="pulse">
                                        { item.pulse }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="temperature">
                                        { item.temperature }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="spo2">
                                        { item.spo2 }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="chief_complaint">
                                        { item.chief_complaint }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="initial_diagnosis">
                                        { item.initial_diagnosis }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="emergency_treatment">
                                        { item.emergency_treatment }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="fluids_iv">
                                        { item.fluids_iv }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!guarantors?.visits_guarantor?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default GuarantorsView;