/** Format a numeric price for display in Iranian Toman (IRT). */ export function formatIrtPrice(value: number | null | undefined): string { if (value === null || value === undefined) return '—' return `${Math.round(value).toLocaleString('en-US')} IRT` } /** Format raw digits into comma-separated groups while typing. */ export function formatIrtInput(raw: string): string { const digits = raw.replace(/\D/g, '') if (!digits) return '' return Number(digits).toLocaleString('en-US') } /** Parse a formatted IRT input string back to a number. */ export function parseIrtInput(formatted: string): number | null { const digits = formatted.replace(/\D/g, '') if (!digits) return null return Number(digits) } export function hasStoreItemDiscount( price: number | null, discountedPrice: number | null, ): boolean { return ( price !== null && discountedPrice !== null && discountedPrice < price && discountedPrice >= 0 ) } export function calcDiscountPercent( price: number, discountedPrice: number, ): number { if (price <= 0 || discountedPrice >= price) return 0 return Math.round((1 - discountedPrice / price) * 100) }