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/rural_doctors/rural_doctorsSlice'
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 Rural_doctorsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { rural_doctors } = useAppSelector((state) => state.rural_doctors)
    

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

              

              

              

              

              

              

              

              

              

              
              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>User</p>
                    
                    
                        <p>{rural_doctors?.user?.firstName ?? 'No data'}</p>
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                </div>
                 
              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>FullName</p>
                    <p>{rural_doctors?.full_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>DHOCode</p>
                    <p>{rural_doctors?.dho_code}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>DoctorRegistrationNo</p>
                    <p>{rural_doctors?.doctor_registration_no}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>AssignedRegion</p>
                    <p>{rural_doctors?.assigned_region}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>SubcenterName</p>
                    <p>{rural_doctors?.subcenter_name}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SubcenterLatitude</p>
                  <p>{rural_doctors?.subcenter_latitude || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              
                <div className={'mb-4'}>
                  <p className={'block font-bold mb-2'}>SubcenterLongitude</p>
                  <p>{rural_doctors?.subcenter_longitude || 'No data'}</p>
                </div>
              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>AvailabilityStatus</p>
                    <p>{rural_doctors?.availability_status ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              

              

              

              

              

              

              

              

              
                <FormField label='CanRegisterPatients'>
                    <SwitchField
                      field={{name: 'can_register_patients', value: rural_doctors?.can_register_patients}}
                      form={{setFieldValue: () => null}}
                      disabled
                    />
                </FormField>
              

              

              

              

              
              

                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Patients RegisteredByRuralDoctor</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                <th>PatientUID</th>
                                
                                
                                
                                <th>FullName</th>
                                
                                
                                
                                <th>Gender</th>
                                
                                
                                
                                <th>DateOfBirth</th>
                                
                                
                                
                                <th>BloodGroup</th>
                                
                                
                                
                                <th>Allergies</th>
                                
                                
                                
                                <th>ChronicConditions</th>
                                
                                
                                
                                <th>EmergencyContactName</th>
                                
                                
                                
                                <th>EmergencyContactPhone</th>
                                
                                
                                
                                
                                
                                <th>RegisteredAt</th>
                                
                                
                                
                                <th>AccountStatus</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {rural_doctors.patients_registered_by_rural_doctor && Array.isArray(rural_doctors.patients_registered_by_rural_doctor) &&
                              rural_doctors.patients_registered_by_rural_doctor.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/patients/patients-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    <td data-label="patient_uid">
                                        { item.patient_uid }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="full_name">
                                        { item.full_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="gender">
                                        { item.gender }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="date_of_birth">
                                        { dataFormatter.dateTimeFormatter(item.date_of_birth) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="blood_group">
                                        { item.blood_group }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="allergies">
                                        { item.allergies }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="chronic_conditions">
                                        { item.chronic_conditions }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="emergency_contact_name">
                                        { item.emergency_contact_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="emergency_contact_phone">
                                        { item.emergency_contact_phone }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="registered_at">
                                        { dataFormatter.dateTimeFormatter(item.registered_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="account_status">
                                        { item.account_status }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!rural_doctors?.patients_registered_by_rural_doctor?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medical_reports AuthorRuralDoctor</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ReportDate</th>
                                
                                
                                
                                <th>ReportType</th>
                                
                                
                                
                                <th>ChiefComplaint</th>
                                
                                
                                
                                <th>Symptoms</th>
                                
                                
                                
                                <th>Diagnosis</th>
                                
                                
                                
                                <th>ClinicalNotes</th>
                                
                                
                                
                                <th>PrescriptionNotes</th>
                                
                                
                                
                                <th>RecommendedTests</th>
                                
                                
                                
                                
                                
                                <th>IsFinalized</th>
                                
                                
                                
                                <th>FinalizedAt</th>
                                
                                
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {rural_doctors.medical_reports_author_rural_doctor && Array.isArray(rural_doctors.medical_reports_author_rural_doctor) &&
                              rural_doctors.medical_reports_author_rural_doctor.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medical_reports/medical_reports-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="report_date">
                                        { dataFormatter.dateTimeFormatter(item.report_date) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="report_type">
                                        { item.report_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="chief_complaint">
                                        { item.chief_complaint }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="symptoms">
                                        { item.symptoms }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="diagnosis">
                                        { item.diagnosis }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="clinical_notes">
                                        { item.clinical_notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="prescription_notes">
                                        { item.prescription_notes }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="recommended_tests">
                                        { item.recommended_tests }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="is_finalized">
                                        { dataFormatter.booleanFormatter(item.is_finalized) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="finalized_at">
                                        { dataFormatter.dateTimeFormatter(item.finalized_at) }
                                    </td>
                                    
                                    
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!rural_doctors?.medical_reports_author_rural_doctor?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Inventory_updates RuralDoctor</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                <th>UpdateType</th>
                                
                                
                                
                                <th>QuantityChange</th>
                                
                                
                                
                                <th>QuantityAfter</th>
                                
                                
                                
                                <th>Reason</th>
                                
                                
                                
                                <th>UpdatedOn</th>
                                
                                
                                
                                <th>IsShortageAlert</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {rural_doctors.inventory_updates_rural_doctor && Array.isArray(rural_doctors.inventory_updates_rural_doctor) &&
                              rural_doctors.inventory_updates_rural_doctor.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/inventory_updates/inventory_updates-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="update_type">
                                        { item.update_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity_change">
                                        { item.quantity_change }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="quantity_after">
                                        { item.quantity_after }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason">
                                        { item.reason }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="updated_on">
                                        { dataFormatter.dateTimeFormatter(item.updated_on) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="is_shortage_alert">
                                        { dataFormatter.booleanFormatter(item.is_shortage_alert) }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!rural_doctors?.inventory_updates_rural_doctor?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medicine_dispatches RequestedByRuralDoctor</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>RequestedAt</th>
                                
                                
                                
                                <th>ApprovedAt</th>
                                
                                
                                
                                <th>DispatchedAt</th>
                                
                                
                                
                                <th>DeliveredAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>DispatchNote</th>
                                
                                
                                
                                <th>DestinationAddress</th>
                                
                                
                                
                                <th>DestinationLatitude</th>
                                
                                
                                
                                <th>DestinationLongitude</th>
                                
                                
                                
                                <th>TrackingReference</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {rural_doctors.medicine_dispatches_requested_by_rural_doctor && Array.isArray(rural_doctors.medicine_dispatches_requested_by_rural_doctor) &&
                              rural_doctors.medicine_dispatches_requested_by_rural_doctor.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medicine_dispatches/medicine_dispatches-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="requested_at">
                                        { dataFormatter.dateTimeFormatter(item.requested_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="approved_at">
                                        { dataFormatter.dateTimeFormatter(item.approved_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dispatched_at">
                                        { dataFormatter.dateTimeFormatter(item.dispatched_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="delivered_at">
                                        { dataFormatter.dateTimeFormatter(item.delivered_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="dispatch_note">
                                        { item.dispatch_note }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="destination_address">
                                        { item.destination_address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="destination_latitude">
                                        { item.destination_latitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="destination_longitude">
                                        { item.destination_longitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="tracking_reference">
                                        { item.tracking_reference }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!rural_doctors?.medicine_dispatches_requested_by_rural_doctor?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medical_camps LeadRuralDoctor</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                <th>CampName</th>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>StartAt</th>
                                
                                
                                
                                <th>EndAt</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>LocationName</th>
                                
                                
                                
                                <th>Address</th>
                                
                                
                                
                                <th>Latitude</th>
                                
                                
                                
                                <th>Longitude</th>
                                
                                
                                
                                <th>ExpectedAttendees</th>
                                
                                
                                
                                <th>ActualAttendees</th>
                                
                                
                                
                                <th>ServicesOffered</th>
                                
                                
                                
                                <th>Notes</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {rural_doctors.medical_camps_lead_rural_doctor && Array.isArray(rural_doctors.medical_camps_lead_rural_doctor) &&
                              rural_doctors.medical_camps_lead_rural_doctor.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/medical_camps/medical_camps-view/?id=${item.id}`)}>
                                    
                                    
                                    <td data-label="camp_name">
                                        { item.camp_name }
                                    </td>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="start_at">
                                        { dataFormatter.dateTimeFormatter(item.start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="end_at">
                                        { dataFormatter.dateTimeFormatter(item.end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="location_name">
                                        { item.location_name }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="address">
                                        { item.address }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="latitude">
                                        { item.latitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="longitude">
                                        { item.longitude }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="expected_attendees">
                                        { item.expected_attendees }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="actual_attendees">
                                        { item.actual_attendees }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="services_offered">
                                        { item.services_offered }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="notes">
                                        { item.notes }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!rural_doctors?.medical_camps_lead_rural_doctor?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                <>
                    <p className={'block font-bold mb-2'}>Appointments RuralDoctor</p>
                    <CardBox
                      className='mb-6 border border-gray-300 rounded overflow-hidden'
                      hasTable
                    >
                        <div className='overflow-x-auto'>
                            <table>
                            <thead>
                            <tr>
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <th>ScheduledStartAt</th>
                                
                                
                                
                                <th>ScheduledEndAt</th>
                                
                                
                                
                                <th>AppointmentType</th>
                                
                                
                                
                                <th>Status</th>
                                
                                
                                
                                <th>ReasonForVisit</th>
                                
                                
                                
                                <th>MeetingLink</th>
                                
                                
                                
                                <th>MeetingRoom</th>
                                
                                
                            </tr>
                            </thead>
                            <tbody>
                            {rural_doctors.appointments_rural_doctor && Array.isArray(rural_doctors.appointments_rural_doctor) &&
                              rural_doctors.appointments_rural_doctor.map((item: any) => (
                                <tr key={item.id} onClick={() => router.push(`/appointments/appointments-view/?id=${item.id}`)}>
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    <td data-label="scheduled_start_at">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_start_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="scheduled_end_at">
                                        { dataFormatter.dateTimeFormatter(item.scheduled_end_at) }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="appointment_type">
                                        { item.appointment_type }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="status">
                                        { item.status }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="reason_for_visit">
                                        { item.reason_for_visit }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="meeting_link">
                                        { item.meeting_link }
                                    </td>
                                    
                                    
                                    
                                    <td data-label="meeting_room">
                                        { item.meeting_room }
                                    </td>
                                    
                                    
                                </tr>
                              ))}
                            </tbody>
                        </table>
                        </div>
                        {!rural_doctors?.appointments_rural_doctor?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default Rural_doctorsView;