import type { FC } from "react"; import { Alert, Group, Stack, Text } from "@mantine/core"; import { useTranslation } from "react-i18next"; import { InstrumentMetric, InstrumentMetrics, InstrumentSection as StockSection, } from "@/features/instrument-details"; import type { StockPageVm } from "../StockPage.vm"; const compactMetricFormatter = new Intl.NumberFormat("ru-RU", { maximumFractionDigits: 2, notation: "compact", }); const metricFormatter = new Intl.NumberFormat("ru-RU", { maximumFractionDigits: 2, notation: "standard", }); type StockCompanyProps = Pick & { stock: NonNullable; }; const StockCompany: FC = (props) => { const { stock } = props; const { t } = useTranslation(); let companyMetricsContent; if (props.company) { if (props.company.metrics.length > 0) { companyMetricsContent = ( {props.company.metrics.map((metric) => { const label = [t(`stock.metrics.${metric.key}`), metric.period].filter(Boolean).join(" · "); const formatter = metric.unit === "money" ? compactMetricFormatter : metricFormatter; const value = `${formatter.format(metric.value)} ${metricUnit(metric)}`; return ( ); })} ); } else { companyMetricsContent = {t("stock.noFundamentals")}; } } return ( {!!stock.sector && ( {t("stock.sector")}:{" "} {t(`stock.sectors.${stock.sector}`, { defaultValue: stock.sector, })} )} {stock.lot !== null && {t("stock.lot", { value: stock.lot })}} {!!props.company && ( {props.company.unavailable.length > 0 && ( {t("stock.partialCompany")} )} {companyMetricsContent} {t("stock.periodNote")} )} ); }; function metricUnit(metric: NonNullable["metrics"][number]) { if (metric.unit === "money") return "₽"; return metric.unit === "percent" ? "%" : "×"; } export { StockCompany };