import React, { useState, useRef, useEffect } from 'react'; import styled from 'styled-components'; import { useCallFeed } from '../hooks/useCallFeed'; import { router } from 'expo-router'; import { Platform, Linking, View, ScrollView, Text, TouchableOpacity } from 'react-native'; import { StatusBar } from 'expo-status-bar'; import { SafeAreaView } from 'react-native-safe-area-context'; import { PageHeader, PageFooter, } from '../components/generalHelpers.jsx'; import { Ionicons } from '@expo/vector-icons'; import { AccidentAndEmergency } from "healthicons-react-native/dist/outline"; import ActionSheet from 'react-native-actions-sheet'; const DepartmentActionSheet = styled(ActionSheet)``; export default function Incidents() { const actionSheetRef = useRef(null); const callFeed = useCallFeed(); const { departments, callIconMap, callDetails, callColorSelector, formatCallTimePast, formatCallDateTime } = callFeed; const sortedAndFilteredCalls = callDetails .sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp)) .filter((item, index, self) => { return index === self.findIndex(i => { return `${i?.data?.Incident?.IncID}${i?.data?.Response?.ServiceName}` === `${item?.data?.Incident?.IncID}${item?.data?.Response?.ServiceName}` }); }); const { departmentTypeMap, accountDetails, deptList, setDeptList, selectedDepartment, setSelectedDepartment, updateSelectedDepartment, selectedDepartmentColorPicker, } = departments; return ( { actionSheetRef.current?.show(); }} > {selectedDepartment?.deptAbv} {sortedAndFilteredCalls?.length ? ( sortedAndFilteredCalls?.map((callItem, index) => { const { data: call, timestamp } = callItem; const { Incident, Address, Response } = call; const { ServiceNumber, IncDate, IncNature, IncNatureCode, IncNatureCodeDesc, Status, } = Incident; const { StreetAddress, AddressApartment, Town, State, LocationName, } = Address; const { ServiceName } = Response; const SelectedIcon = callIconMap[IncNature] || AccidentAndEmergency; return ( { router.push({ pathname: '/call', params: { callDetails: btoa(JSON.stringify(call)) } }) }} > {formatCallDateTime(IncDate)} {formatCallTimePast(IncDate)} {Status === 'CLOSED' ? ( ) : null} {LocationName ? ( {`${LocationName}`} ) : ( {`${StreetAddress}`} {AddressApartment ? ( {` - ${AddressApartment}`} ) : null } {` ${Town}, ${State}`} )} {`${IncNature}`} {`${IncNatureCodeDesc}`} Service: {ServiceName} {`Incident #: ${ServiceNumber}`} ) })) : ( There are no Calls ) } {deptList?.map((item) => { return ( { actionSheetRef.current?.hide(); return updateSelectedDepartment( selectedDepartment?.deptId, item?.deptId ) }} > {item?.dept} {item?.primary ? : null} {`${item?.deptAbv} - ${departmentTypeMap[item?.type]}`} ); })} ) }