'use client'; import { FunctionComponent } from 'react'; import { useLocale, useTranslations } from 'next-intl'; import { Stack, Typography } from '@mui/material'; import StatusChip from '../StatusChip'; import Money from '@/components/common/Money'; import SurfaceCard from '@/components/common/SurfaceCard'; import { formatShamsiDate } from '@/utils'; import { installmentStatusKind, type BnplInstallmentRow, type BnplInstallmentStatus } from '@/services/bnpl/types'; export interface InstallmentScheduleRowProps { row: BnplInstallmentRow; /** Render the provider-reported status chip (D5 Wallet). The D4 schedule preview omits it. */ showStatus?: boolean; } /** i18n key for each provider-reported installment status (labels are keys off the code, never derived). */ const STATUS_LABEL_KEY: Record = { paid: 'status_paid', due_soon: 'status_due_soon', upcoming: 'status_upcoming', overdue: 'status_overdue', }; /** * One repayment row — the down-payment (due «امروز») or an installment (Shamsi due date), with the * **served** amount (Toman via the money util). Reused by the D4 schedule table and the D5 Wallet due list; * `showStatus` adds the provider-reported status chip (D5). No money is computed here — display only. * @component InstallmentScheduleRow */ const InstallmentScheduleRow: FunctionComponent = ({ row, showStatus = false }) => { const t = useTranslations('bnpl'); const locale = useLocale(); const label = row.kind === 'down_payment' ? t('down_payment') : t('installment_n', { n: row.sequence }); const dueLabel = row.kind === 'down_payment' ? t('today') : formatShamsiDate(`${row.dueDate}T00:00:00`, locale); return ( {label} {dueLabel} {showStatus && row.status ? ( ) : null} ); }; export default InstallmentScheduleRow;