import { Trans } from "react-i18next"; import { OpenHandsAction } from "#/types/core/actions"; import { isOpenHandsAction, isOpenHandsObservation } from "#/types/core/guards"; import { OpenHandsObservation } from "#/types/core/observations"; import { MonoComponent } from "../mono-component"; import { PathComponent } from "../path-component"; import { getActionContent } from "./get-action-content"; import { getObservationContent } from "./get-observation-content"; import i18n from "#/i18n"; const hasPathProperty = ( obj: Record, ): obj is { path: string } => typeof obj.path === "string"; const hasCommandProperty = ( obj: Record, ): obj is { command: string } => typeof obj.command === "string"; const trimText = (text: string, maxLength: number): string => { if (!text) return ""; return text.length > maxLength ? `${text.substring(0, maxLength)}...` : text; }; export const getEventContent = ( event: OpenHandsAction | OpenHandsObservation, ) => { let title: React.ReactNode = ""; let details: string = ""; if (isOpenHandsAction(event)) { const actionKey = `ACTION_MESSAGE$${event.action.toUpperCase()}`; // If translation key exists, use Trans component if (i18n.exists(actionKey)) { title = ( , cmd: , }} /> ); } else { // For generic actions, just use the uppercase type title = event.action.toUpperCase(); } details = getActionContent(event); } if (isOpenHandsObservation(event)) { const observationKey = `OBSERVATION_MESSAGE$${event.observation.toUpperCase()}`; // If translation key exists, use Trans component if (i18n.exists(observationKey)) { title = ( , cmd: , }} /> ); } else { // For generic observations, just use the uppercase type title = event.observation.toUpperCase(); } details = getObservationContent(event); } return { title: title ?? i18n.t("EVENT$UNKNOWN_EVENT"), details: details ?? i18n.t("EVENT$UNKNOWN_EVENT"), }; };