Files
CRM_Montzar/apps/web/src/components/gamification/rule-text.ts
T

16 lines
833 B
TypeScript
Raw Normal View History

import type { GamificationCondition } from '@mento/shared';
import { GAMIFICATION_CONDITION_OPS, GAMIFICATION_FIELDS } from '@mento/shared';
import { toFaDigits } from '@/lib/jalali';
/** متن خوانا برای یک شرط، مثل «مبلغ بیشتر از ۱۰۰٬۰۰۰» */
export function conditionText(c: GamificationCondition): string {
const field = GAMIFICATION_FIELDS[c.field];
const label = field?.label ?? c.field;
if (c.op === 'is_true') return `${label}: بله`;
if (c.op === 'is_false') return `${label}: خیر`;
const raw = c.value ?? '';
const option = field?.options?.find((o) => o.value === String(raw));
const value = option ? option.label : typeof raw === 'number' ? toFaDigits(raw.toLocaleString('en-US')) : String(raw);
return `${label} ${GAMIFICATION_CONDITION_OPS[c.op]} ${value}`;
}