import React, { useCallback, useMemo } from "react"; import { deepEqual } from "fast-equals"; import { View } from "react-native"; import { IconButton, TouchableRipple } from "react-native-paper"; import { MaterialCommunityIcons } from "@expo/vector-icons"; import Maplibre from "@maplibre/maplibre-react-native"; import Text from "~/components/Text"; import useTimeDisplay from "~/hooks/useTimeDisplay"; import { useNavigation } from "@react-navigation/native"; import { createStyles, useTheme } from "~/theme"; import { alertActions } from "~/stores"; export default function SelectedFeatureBubbleAlert({ feature, close }) { const { properties = {} } = feature; const { alert } = properties; const styles = useStyles(); const { colors, custom } = useTheme(); const createdAtText = useTimeDisplay(alert.createdAt); const navigation = useNavigation(); const goToAlert = useCallback(() => { alertActions.setNavAlertCur({ alert }); navigation.navigate({ name: "AlertCur", params: { screen: "AlertCurTab", params: { screen: "AlertCurOverview", }, }, }); }, [alert, navigation]); const { level } = alert; const levelColor = custom.appColors[level]; return ( ( )} onPress={() => close()} /> {useMemo(() => { const isLocationsDifferent = alert.initialLocation && alert.location && !deepEqual(alert.initialLocation, alert.location); if (isLocationsDifferent) { return ( {alert.followLocation ? "Localisation actuelle" : "Dernière position connue"} ); } return null; }, [ alert.initialLocation, alert.location, alert.followLocation, styles.titleContainer, styles.titleText, ])} Sujet : {alert.subject || "non indiqué"} Code : #{alert.code} Envoyée par : {alert.username} {createdAtText} Depuis l'adresse : {alert.address} Localisation en 3 mots : {alert.what3Words} Situation ); } const useStyles = createStyles(({ wp, fontSize, theme: { colors } }) => ({ bubbleContainer: { backgroundColor: colors.surface, justifyContent: "center", alignItems: "flex-start", paddingHorizontal: 4, paddingVertical: 2, borderRadius: 5, // width: "100%", width: wp(75), }, bubbleText: { color: colors.onSurface, fontSize: 16, }, closeButton: {}, closeButtonIcon: { color: colors.grey, }, content: { paddingHorizontal: 4, }, titleContainer: { marginBottom: 8, borderBottomWidth: 1, borderBottomColor: colors.grey, paddingBottom: 4, }, titleText: { color: colors.primary, fontSize: 16, fontWeight: "bold", textAlign: "center", }, contentLine: { flexDirection: "row", justifyContent: "space-between", flexWrap: "wrap", }, contentText: { color: colors.onSurface, fontSize: 15, paddingRight: 5, }, contentTextValue: { color: colors.onSurfaceVariant, fontSize: 15, paddingRight: 5, textAlign: "right", flexGrow: 1, }, alertLinkButton: { marginTop: 15, marginBottom: 5, borderRadius: 0, paddingVertical: 0, backgroundColor: colors.primary, }, alertLinkContent: { height: 28, flexDirection: "row", alignItems: "center", justifyContent: "center", }, alertLinkText: { color: colors.surface, fontSize: 15, }, alertLinkButtonIcon: { color: colors.surface, marginRight: 5, fontSize: 15, }, }));