import React, { useState, useRef, useEffect } from "react"; import styled from "styled-components"; import { useCallFeed } from "@/hooks"; 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)``; function toBase64Unicode(str) { return btoa( new TextEncoder() .encode(str) .reduce((data, byte) => data + String.fromCharCode(byte), "") ); } 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?.incident?.incID}${i?.response?.serviceName}` === `${item?.incident?.incID}${item?.response?.serviceName}` ); }) ); }) ?.map((item) => { return { ...item, timestamp: item?.incident?.incDate }; }) || []; const { departmentTypeMap, accountDetails, deptList, setDeptList, selectedDepartment, setSelectedDepartment, updateSelectedDepartment, selectedDepartmentColorPicker, } = departments; return ( { actionSheetRef.current?.show(); }} > {selectedDepartment?.deptAbv} } /> {sortedAndFilteredCalls?.length ? ( sortedAndFilteredCalls?.map((callItem, index) => { const { incident, address, response, timestamp } = callItem; 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: toBase64Unicode(JSON.stringify(callItem)), }, }); }} > {formatCallDateTime(incDate)} {formatCallTimePast(incDate)} {status === "CLOSED" ? ( ) : null} {locationName ? ( {`${locationName}`} ) : ( {`${streetAddress?.split(",")[0]}`} {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] }`} ); })} ); }