52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import homeImg from '@/assets/img/cash_home.svg'
|
||||
|
|
import giftImg from '@/assets/img/cash_gift.svg'
|
|||
|
|
import circulationImg from '@/assets/img/cash_circulation.svg'
|
|||
|
|
import loveImg from '@/assets/img/cash_love.svg'
|
|||
|
|
import repairsImg from '@/assets/img/cash_repairs.svg'
|
|||
|
|
import savingImg from '@/assets/img/cash_saving.svg'
|
|||
|
|
import type { Fund } from '@/models/fund'
|
|||
|
|
|
|||
|
|
export const PIGGY_PRESETS = [
|
|||
|
|
'پس انداز',
|
|||
|
|
'هدیه',
|
|||
|
|
'ازدواج',
|
|||
|
|
'تعمیرات',
|
|||
|
|
'گردش',
|
|||
|
|
'خرید لوازم منزل',
|
|||
|
|
] as const
|
|||
|
|
|
|||
|
|
export function piggyIconForTitle(title?: string | null): string {
|
|||
|
|
switch ((title ?? '').trim()) {
|
|||
|
|
case 'خرید لوازم منزل':
|
|||
|
|
return homeImg
|
|||
|
|
case 'هدیه':
|
|||
|
|
return giftImg
|
|||
|
|
case 'گردش':
|
|||
|
|
return circulationImg
|
|||
|
|
case 'ازدواج':
|
|||
|
|
return loveImg
|
|||
|
|
case 'تعمیرات':
|
|||
|
|
return repairsImg
|
|||
|
|
case 'پس انداز':
|
|||
|
|
default:
|
|||
|
|
return savingImg
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function fundWalletGold(item?: Fund | null): number {
|
|||
|
|
if (!item) return 0
|
|||
|
|
const wallets = Array.isArray(item.wallet) ? item.wallet : item.wallet ? [item.wallet] : []
|
|||
|
|
return wallets.reduce((acc, w) => acc + Number((w as { gold?: number })?.gold ?? 0), 0)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function fundProductLabel(item?: Fund | null): string {
|
|||
|
|
if (!item) return '—'
|
|||
|
|
return item.product?.title || (item as { product_title?: string }).product_title || '—'
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function formatPiggyAmount(value: number): string {
|
|||
|
|
const n = Number(value) || 0
|
|||
|
|
if (Math.abs(n) < 0.0005) return '۰'
|
|||
|
|
return n.toLocaleString('fa-IR', { maximumFractionDigits: 3 })
|
|||
|
|
}
|