import { Feather } from "@expo/vector-icons"; import type { NotificationActionState, NotificationType } from "./types"; export type NotificationPalette = { background: string; foreground: string; accent: string; }; const neutral: NotificationPalette = { background: "#f3f3f5", foreground: "#252525", accent: "#030213", }; const palettes: Record = { critical: { background: "#feecef", foreground: "#7f1d1d", accent: "#d4183d" }, warning: { background: "#fff7df", foreground: "#713f12", accent: "#ca8a04" }, success: { background: "#eaf8ee", foreground: "#14532d", accent: "#16a34a" }, info: { background: "#eaf2ff", foreground: "#1e3a8a", accent: "#2563eb" }, promo: { background: "#f4edff", foreground: "#4c1d95", accent: "#7c3aed" }, neutral, }; const icons: Record = { alert: "alert-circle", urgent: "alert-triangle", payment: "credit-card", documents: "file-text", document: "file-text", status: "activity", reminder: "clock", news: "bell", promo: "gift", ads: "star", authorize: "log-in", install: "download", info: "info", }; export function notificationPalette(token?: string | null): NotificationPalette { return token ? (palettes[token] ?? neutral) : neutral; } export function notificationIcon(code?: string | null): keyof typeof Feather.glyphMap { return code ? (icons[code] ?? "bell") : "bell"; } export function typeMap(catalog: NotificationType[]) { return new Map(catalog.map((type) => [type.code, type])); } export function formatNotificationPrice(value?: number | string | null) { if (value === null || value === undefined) return null; const number = Number(value); if (!Number.isFinite(number)) return null; return new Intl.NumberFormat("ru-RU", { style: "currency", currency: "RUB", maximumFractionDigits: number % 1 === 0 ? 0 : 2, }).format(number); } export function actionUrl(state: NotificationActionState) { return state.result?.action === "open_url" ? state.result.url : undefined; } export function actionDialogId(state: NotificationActionState) { return state.result?.action === "chat_message_sent" ? state.result.message.dialog_id : undefined; } export function openNewTab(url: string) { if (typeof window !== "undefined") { window.open(url, "_blank", "noopener,noreferrer"); return; } void import("react-native").then(({ Linking }) => Linking.openURL(url)); }