import { RtTooltipPlacement, RtTooltipProps } from '../rt-tooltip.types'; import { mapAlignment, mapPositionRTL, mapPositionLTR } from './map-position'; import { RefObject } from 'react'; type TRelativePlacement = 'bottom' | 'top' | 'left' | 'right'; export const mapPlacementProps = ( position: TRelativePlacement, alignment: NonNullable ): RtTooltipPlacement => { return `${position}${mapAlignment[alignment]}`; }; export const getRelativePlacement = ( position: NonNullable, ref?: RefObject ): TRelativePlacement => { const isFlipped = typeof window !== 'undefined' && ref?.current ? getComputedStyle(ref.current as Element)?.direction === 'rtl' : false; return (isFlipped ? mapPositionRTL : mapPositionLTR)[position]; };