import { useDocumentTitle } from "@mantine/hooks"; import type { FC } from "react"; import { useTranslation } from "react-i18next"; import { useMatch } from "react-router"; 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) => { const { t } = useTranslation(); useDocumentTitle(`${props.title} — ${t("appName")}`); return null; }; 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")); const section = props.section === "income" ? t("income.title") : props.section === "operations" ? t("ledger.title") : props.section === "events" ? t("events.title") : t("portfolio.title"); 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 = useMatch("/accounts/:accountId/:section?"); const bond = useMatch("/bonds/:bondId"); const stock = useMatch("/stocks/:stockId"); const card = useMatch("/cards/:cardId"); const cards = useMatch("/cards"); const bonds = useMatch("/bonds"); const stocks = useMatch("/stocks"); const settings = useMatch("/settings"); if (card) return ; if (account) return ( ); if (bond) return ; if (stock) return ; return ( ); }; export { ProtectedDocumentTitle };