import type { FC } from "react"; import { AreaChart } from "@mantine/charts"; import { Accordion, Badge, ScrollArea, SegmentedControl, Table, Text, } from "@mantine/core"; import { useTranslation } from "react-i18next"; import { formatDecimal, formatMoney } from "@/shared/lib"; import type { InstrumentChartVm } from "../model/types"; import classes from "./InstrumentDetails.module.css"; import { InstrumentSection } from "./InstrumentSection.view"; type InstrumentChartProps = { priceUnit?: "percent"; vm: InstrumentChartVm }; const InstrumentChart: FC = (props) => { const { vm } = props; const { t } = useTranslation(); const priceLabel = (value: string) => { if (props.priceUnit === "percent") return `${formatDecimal(value)} %`; const currency = vm.candles?.currency; return formatMoney(currency ? { currency, value } : undefined); }; return ( ({ label: t(`stock.periods.${value}`), value, }))} onChange={vm.setPeriod} value={vm.period} /> )} large state={vm.candlesState} title={t("stock.chart")} > {!!(vm.candles) && (( vm.chartData.length > 0 ? ( <> new Intl.NumberFormat("ru-RU", { maximumFractionDigits: 4, }).format(value)} withDots={vm.chartData.length === 1} withGradient yAxisProps={{ domain: ["auto", "auto"], width: 64 }} /> {t( props.priceUnit === "percent" ? "bond.chartNote" : "stock.chartNote", )} {!!(vm.hasIncompleteCandle) && (( {t("stock.incomplete")} ))} {vm.averageLine !== null && (( {t("stock.averageLine")} : {" "} {formatMoney(vm.position?.averagePurchasePrice)} ))} {t("stock.priceTable")} {t("stock.priceTableHint", { count: vm.chartData.length })} {t("stock.date")} {t("stock.price")} {t("stock.candle")} {vm.priceRows.map(candle => ( {candle.date} {priceLabel(candle.close)} {t( candle.isComplete ? "stock.complete" : "stock.forming", )} ))}
) : ( {t( vm.candlesState.partial ? "investment.partial" : "stock.noCandles", )} ) ))}
); }; export { InstrumentChart };