import React, { useRef } from 'react'; import styled from 'styled-components'; import { router } from 'expo-router'; import { useCallFeed } from '../hooks/useCallFeed'; import { Platform, Linking, View, ScrollView, Text, TouchableOpacity } from 'react-native'; import { useLocalSearchParams } from 'expo-router'; import { StatusBar } from 'expo-status-bar'; import { SafeAreaView } from 'react-native-safe-area-context'; import { Ionicons } from '@expo/vector-icons'; import { AccidentAndEmergency } from "healthicons-react-native/dist/outline"; import { Phone } from "healthicons-react-native/dist/filled"; import { PageHeader, PageFooter, } from '@/components/generalHelpers.jsx'; import ActionSheet from 'react-native-actions-sheet'; const DepartmentActionSheet = styled(ActionSheet)``; function fromBase64Unicode(str) { return new TextDecoder().decode(Uint8Array.from(atob(str), c => c.charCodeAt(0))); } export default function Call() { const { callDetails } = useLocalSearchParams(); const actionSheetRef = useRef(null); const callFeed = useCallFeed(true); const { departments, callIconMap, callColorSelector, formatCallTimePast, formatCallDateTime } = callFeed; const { departmentTypeMap, accountDetails, selectedDepartment, setSelectedDepartment, updateSelectedDepartment, selectedDepartmentColorPicker, deptList, } = departments; const decoded = fromBase64Unicode(callDetails); const { incident, address, person, response } = JSON.parse(decoded); const { CallThemes } = accountDetails; const { incID, incNumber, jurisdictionNumber, serviceNumber, serviceID, incDate, incNature, incNatureCode, incNatureCodeDesc, notes, status, origin, } = incident; const { streetAddress, addressApartment, town, state, zipCode, latitude, longitude, county, intersection1, intersection2, locationName, weatherCondition, } = address; const { name, age, gender, statement, conscious, breathing, callBackNumber, } = person; const { units } = response; const SelectedIcon = callIconMap[incNature] || AccidentAndEmergency; const ownDepartmentResponse = units?.map((unit) => { if (unit?.department === selectedDepartment?.dept || selectedDepartment?.addDepts?.includes(unit?.department)) { return unit; } return null; })?.filter((filterItem) => { return filterItem; }); const mutualAidDepartmentResponse = units?.map((unit) => { if (unit?.department !== selectedDepartment?.dept && !selectedDepartment?.addDepts?.includes(unit?.department)) { return unit; } return null; })?.filter((filterItem) => { return filterItem; });; const formatResponseTimes = (time) => { if (time === null || time === undefined || time === '') { return ''; } const initTime = new Date(time); const hours = initTime.getHours().toString().padStart(2, '0'); const minutes = initTime.getMinutes().toString().padStart(2, '0'); return `${hours}:${minutes}`; }; const openMaps = (latitude, longitude) => { const daddr = `${latitude},${longitude}`; const company = Platform.OS === "ios" ? "apple" : "google"; Linking.openURL(`http://maps.${company}.com/maps?daddr=${daddr}`); }; const callNumber = (number) => { const formattedNumber = number.replace(/[()\-\s]/g, ''); Linking.openURL(`tel:${formattedNumber}`); }; return ( Back to Incidents } centerHeader={ { actionSheetRef.current?.show(); }} > {selectedDepartment?.deptAbv} } /> {formatCallDateTime(incDate)} {formatCallTimePast(incDate)} {`${incNature}`} {`${incNatureCodeDesc}`} {status.toLowerCase() === 'closed' ? ( This Incident is Closed. ) : } {`Incident #: ${serviceNumber}`} {locationName ? ( {`${locationName}`} ) : null} { return openMaps(latitude, longitude); }} > {`${streetAddress}`} {`${town}, ${state}`} {addressApartment ? ( {`${addressApartment}`} ) : null} Map { return openMaps(latitude, longitude); }} > Nav {intersection1} {intersection2} {selectedDepartment?.supervisor ? ( {`${name}`} { return callNumber(callBackNumber); }} > {`${callBackNumber}`} { return callNumber(callBackNumber); }} > ) : null} {`${age} `} {`${gender} - `} {`Conscious: ${conscious} | `} {`Breathing: ${breathing}`} {`${statement}`} {units?.length > 0 ? ( {ownDepartmentResponse?.length > 0 ? ( Units Disp Resp Arr {selectedDepartment?.type === 'EMS' || selectedDepartment?.type === 'Rescue' ? ( Trans ) : null} BIS {ownDepartmentResponse?.map((unit) => { return ( {unit?.unit} {formatResponseTimes(unit?.dispatched)} {formatResponseTimes(unit?.responding)} {formatResponseTimes(unit?.onScene)} {selectedDepartment?.type === 'EMS' || selectedDepartment?.type === 'Rescue' ? ( {formatResponseTimes(unit?.transporting)} ) : null} {formatResponseTimes(unit?.inService)} ) })} ) : ( {`No ${selectedDepartment?.dept} Units Responding`} )} {mutualAidDepartmentResponse?.length > 0 ? ( M/A Disp Resp Arr {selectedDepartment?.type === 'EMS' || selectedDepartment?.type === 'Rescue' ? ( Trans ) : null} BIS {mutualAidDepartmentResponse?.map((unit) => { return ( {unit?.unit} {formatResponseTimes(unit?.dispatched)} {formatResponseTimes(unit?.responding)} {formatResponseTimes(unit?.onScene)} {selectedDepartment?.type === 'EMS' || selectedDepartment?.type === 'Rescue' ? ( {formatResponseTimes(unit?.transporting)} ) : null} {formatResponseTimes(unit?.inService)} ) })} ) : null} ) : ( No Units Responding )} Incident Notes {notes?.split('\n').map((note, index) => ( {note} {index < notes.split('\n').length - 1 && ( )} ))} {deptList?.map((item) => { return ( { actionSheetRef.current?.hide(); return updateSelectedDepartment( selectedDepartment?.deptId, item?.deptId ) }} > {item?.dept} {item?.primary ? : null} {`${item?.deptAbv} - ${departmentTypeMap[item?.type]}`} ); })} ); }