import React, { useRef } from 'react'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { Button, ClickableTile, Tile } from '@carbon/react'; import { TrashCan, Warning } from '@carbon/react/icons'; import { useLayoutType } from '@openmrs/esm-framework'; import styles from './imaging-order-basket-item-tile.scss'; import { type ImagingOrderBasketItem } from '../../../types'; export interface OrderBasketItemTileProps { orderBasketItem: ImagingOrderBasketItem; onItemClick: () => void; onRemoveClick: () => void; } export function ImagingOrderBasketItemTile({ orderBasketItem, onItemClick, onRemoveClick }: OrderBasketItemTileProps) { const { t } = useTranslation(); const isTablet = useLayoutType() === 'tablet'; // This here is really dirty, but required. // If the ref's value is false, we won't react to the ClickableTile's handleClick function. // Why is this necessary? // The "Remove" button is nested inside the ClickableTile. If the button's clicked, the tile also raises the // handleClick event later. Not sure if this is a bug, but this shouldn't be possible in our flows. // Hence, we manually prevent the handleClick callback from being invoked as soon as the button is pressed once. const shouldOnClickBeCalled = useRef(true); const labTile = (