import React, { ReactNode } from 'react'; import HoverInfo from 'app/shared/components/hoverInfo/hoverInfo'; import cx from 'classnames'; import numberPipe from 'app/shared/pipes/number.pipe'; import moneyPipe from 'app/shared/pipes/money.pipe'; import { OffHireContainer } from 'app/shared/containers/offHire/offHire.container'; export interface Figures { value?: number | string | null; totalValue?: number; type: 'money' | 'number' | 'text' | 'offhire' | 'comparison'; iconStyles?: string; description: string; additionalDescription?: string unit?: string; } export interface Props { header?: string; hint?: ReactNode; hintIcon?: string; boxes: Figures[]; } const getValue = ({ value, totalValue, type }: Figures) => { if (value === null || value === undefined) { return '-'; } switch (type) { case 'money': return moneyPipe.prefixedFormat(Number(value)); case 'number': return numberPipe.format(Number(value), 2); case 'text': return value; case 'comparison': return ( <> {value} of {totalValue} ); default: return value; } }; const InfoBox = ({ header, hint, hintIcon='icon-info-straight', boxes }: Props) => { return (
{header &&
{header} {hintIcon && hint && {hint} }
} {boxes && boxes.map(((box, index) => { const isFirst = index === 0; const classes = cx('o-layout o-layout--aligned', 'u-no-wrap', { 'u-margin-top--medium': !isFirst }); return ( <>
{getValue(box)} {box.unit && {box.unit}} {(box.type ==='offhire') && }
{box.description} {box.additionalDescription && {box.additionalDescription}} ); }))}
); }; export { InfoBox };