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/admins/adminsSlice'
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 AdminsView = () => {
    const router = useRouter()
    const dispatch = useAppDispatch()
    const { admins } = useAppSelector((state) => state.admins)
    

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

              

              

              

              

              

              

              

              

              

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

              

              

              
              

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

              

              

              

              

              

              

              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>GmailAddress</p>
                    <p>{admins?.gmail_address}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

              

              

              

              

              

              

              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>AccessLevel</p>
                    <p>{admins?.access_level ?? 'No data'}</p>
                </div>
              

              

              

              

              

              
              

              
                <div className={'mb-4'}>
                    <p className={'block font-bold mb-2'}>Department</p>
                    <p>{admins?.department}</p>
                </div>
              

              

              

              

              

              

              

              

              

              

              

              

              
              

                
                
                
                
                
                
                
                
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medicine_dispatches ApprovedByAdmin</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>
                            {admins.medicine_dispatches_approved_by_admin && Array.isArray(admins.medicine_dispatches_approved_by_admin) &&
                              admins.medicine_dispatches_approved_by_admin.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>
                        {!admins?.medicine_dispatches_approved_by_admin?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                <>
                    <p className={'block font-bold mb-2'}>Medical_camps CreatedByAdmin</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>
                            {admins.medical_camps_created_by_admin && Array.isArray(admins.medical_camps_created_by_admin) &&
                              admins.medical_camps_created_by_admin.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>
                        {!admins?.medical_camps_created_by_admin?.length && <div className={'text-center py-4'}>No data</div>}
                    </CardBox>
                </>
                
                
                
                
                
                
                
                
                
                
                
                
                

                <BaseDivider />

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

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

export default AdminsView;