import type { FC } from "react"; import { useDocumentTitle } from "@mantine/hooks"; import { useTranslation } from "react-i18next"; import { useCurrentRoute } from "@/app/model"; import { useBankCard } from "@/entities/bank-card"; import { useBond } from "@/entities/bond"; import { useBrokerageAccounts } from "@/entities/brokerage-account"; import { useStock } from "@/entities/stock"; type DocumentTitleProps = { title: string }; const DocumentTitle: FC = (props): undefined => { const { t } = useTranslation(); useDocumentTitle(`${props.title} — ${t("appName")}`); }; type AccountDocumentTitleProps = { accountId: string; section?: string; }; const AccountDocumentTitle: FC = (props) => { const { t } = useTranslation(); const { data } = useBrokerageAccounts(); const accountName = props.accountId === "all" ? t("accounts.all") : (data?.find(account => account.id === props.accountId)?.name ?? t("account.title")); let section = t("portfolio.title"); switch (props.section ?? "") { case "income": { section = t("income.title"); break; } case "operations": { section = t("ledger.title"); break; } case "events": { section = t("events.title"); break; } default: { break; } } return ; }; type InstrumentDocumentTitleProps = { identifier: string }; const BondDocumentTitle: FC = (props) => { const { t } = useTranslation(); const { data } = useBond(props.identifier); return ; }; const StockDocumentTitle: FC = (props) => { const { t } = useTranslation(); const { data } = useStock(props.identifier); return ; }; const CardDocumentTitle: FC = (props) => { const { t } = useTranslation(); const { data } = useBankCard(props.identifier); return ; }; const ProtectedDocumentTitle: FC = () => { const { t } = useTranslation(); const { account, bond, bonds, card, cards, settings, stock, stocks, } = useCurrentRoute(); if (card) return ; if (account) return ( ); if (bond) return ; if (stock) return ; if (cards) return ; if (bonds) return ; if (stocks) return ; return settings ? : ; }; export { ProtectedDocumentTitle };