import type { OperationIconProps } from "@wealthledger/icons"; import type { BankOperation } from "../api/types"; const categoryIcons: { appearance: OperationIconProps; name: string; }[] = [ { appearance: { color: "grape", variant: "wine" }, name: "Алкоголь" }, { appearance: { color: "green", variant: "deposit" }, name: "Вклады" }, { appearance: { color: "orange", variant: "home" }, name: "Жильё" }, { appearance: { color: "red", variant: "medical" }, name: "Здоровье" }, { appearance: { color: "green", variant: "growth" }, name: "Инвестиции и накопления", }, { appearance: { color: "orange", variant: "coffee" }, name: "Кафе" }, { appearance: { color: "blue", variant: "education" }, name: "Образование" }, { appearance: { color: "blue", variant: "transfer" }, name: "Переводы" }, { appearance: { color: "orange", variant: "repayment" }, name: "Погашение кредита", }, { appearance: { color: "grape", variant: "subscriptions" }, name: "Подписки", }, { appearance: { color: "grape", variant: "shopping" }, name: "Покупки" }, { appearance: { color: "green", variant: "basket" }, name: "Продукты" }, { appearance: { color: "blue", variant: "travel" }, name: "Путешествия" }, { appearance: { color: "grape", variant: "music" }, name: "Развлечения" }, { appearance: { color: "blue", variant: "wifi" }, name: "Связь и интернет" }, { appearance: { color: "green", variant: "cashWithdrawal" }, name: "Снятие наличных", }, { appearance: { color: "grape", variant: "dice" }, name: "Ставки" }, { appearance: { color: "green", variant: "shield" }, name: "Страхование" }, { appearance: { color: "orange", variant: "smoking" }, name: "Табак" }, { appearance: { color: "yellow", variant: "taxi" }, name: "Такси" }, { appearance: { color: "blue", variant: "car" }, name: "Транспорт" }, { appearance: { color: "grape", variant: "server" }, name: "Хостинг и ИИ-сервисы", }, { appearance: { color: "blue", variant: "download" }, name: "Цифровые покупки", }, ]; const otherIcon: OperationIconProps = { color: "gray", variant: "grid", }; const operationIcons: Record< Exclude, OperationIconProps > = { refund: { color: "teal", variant: "refund" }, topup: { color: "green", variant: "topup", }, transfer: { color: "blue", variant: "transfer", }, }; function bankOperationAppearance( kind: BankOperation["kind"], categoryName?: null | string, ) { if (kind !== "expense") // eslint-disable-next-line security/detect-object-injection -- Operation kinds are a finite API union. return operationIcons[kind]; const name = normalizeCategoryName(categoryName ?? ""); const category = categoryIcons.find( item => normalizeCategoryName(item.name) === name, ); return category?.appearance ?? otherIcon; } function normalizeCategoryName(name: string) { return name.trim().toLocaleLowerCase("ru-RU").replaceAll("ё", "е"); } export { bankOperationAppearance };