import { Paper, Stack, Text, Title } from "@mantine/core"; import type { FC } from "react"; import { useTranslation } from "react-i18next"; import { formatMoney } from "@/shared/lib"; import classes from "../AccountIncomePage.module.css"; import type { IncomeDisplayModel } from "../AccountIncomePage.vm"; type IncomeComparisonsProps = { comparison: IncomeDisplayModel["comparison"] }; type ComparisonProps = NonNullable; type ComparisonValuesProps = { kind: "selected" | "compared" | "difference"; label: string; values: ComparisonProps["values"][number]["selected"]; percentages?: ComparisonProps["values"][number]["percentages"]; }; const IncomeComparisons: FC = (props) => { const { t } = useTranslation(); return ( {t("income.yearAgo")} {props.comparison ? ( ) : ( {t("income.yearUnavailable")} )} ); }; const Comparison: FC = (props) => { const { t } = useTranslation(); return (
{props.values.map((value) => (
))} {props.values.length === 0 ? ( {t("income.comparisonEmpty")} ) : null}
); }; const ComparisonValues: FC = (props) => { const { t } = useTranslation(); return (
{props.label}
{(["total", "coupon", "dividend"] as const).map((key) => { const money = props.values[key]; const percentage = props.percentages?.[key]; const tone = props.kind === "difference" ? differenceTone(money.value) : undefined; return (
{t(`income.${key}`)}
{tone === "positive" ? "+" : ""} {formatMoney(money)} {percentage ? ( {percentage} ) : null}
); })}
); }; function differenceTone(value: string): "positive" | "negative" | "neutral" { if (!/[1-9]/.test(value)) return "neutral"; return value.startsWith("-") ? "negative" : "positive"; } export { IncomeComparisons };