'use client'; import { FunctionComponent } from 'react'; import { useLocale, useTranslations } from 'next-intl'; import { Box, Paper, Skeleton, Stack, Typography } from '@mui/material'; import { AppButton, AppIcon, InstallmentScheduleRow, Money, PlaceholderScreen } from '@/components'; import { formatShamsiDate } from '@/utils'; import { useWalletInstallments } from '@/services/bnpl'; import type { WalletInstallmentPlan } from '@/services/bnpl/types'; /** * D5 · پیگیری اقساط — the Wallet «اقساط» section (active installment plans). It reads * `useWalletInstallments` and renders **provider-reported** status: an outstanding-balance card * (terracotta), the next-installment date + a provider hand-off «پرداخت زودهنگام» (early-pay is a * *provider* action, never a Balinyaar transaction), the per-installment due list with status chips, and * the ownership note (Balinyaar displays, it does not manage, this schedule). Section body only — the * page-level heading + tab strip live in `WalletScreen`. */ const WalletInstallments: FunctionComponent = () => { const t = useTranslations('bnpl'); const tc = useTranslations('common'); const { data: plans, isLoading, isError, refetch } = useWalletInstallments(); return ( {isLoading ? ( ) : isError ? ( {t('wallet_error_title')} {t('wallet_error_body')} refetch()} sx={{ mt: 1 }}> {tc('retry')} ) : !plans || plans.length === 0 ? ( ) : ( {plans.map((plan) => ( ))} )} ); }; function InstallmentPlanSection({ plan }: { plan: WalletInstallmentPlan }) { const t = useTranslations('bnpl'); const locale = useLocale(); const providerName = t(`provider_${plan.providerCode}`); const handleEarlyPay = () => { // Early-pay is a PROVIDER action — hand off to the provider, never a Balinyaar payment. if (plan.earlyPayUrl) window.open(plan.earlyPayUrl, '_blank', 'noopener,noreferrer'); }; return ( {/* Outstanding-balance card — terracotta financial accent; contrast text is scheme-stable. */} {t('outstanding_balance')} {plan.serviceLabel} {plan.nextDueDate ? ( {t('next_installment')} · {formatShamsiDate(`${plan.nextDueDate}T00:00:00`, locale)} {plan.nextAmountIrr ? ( ) : null} {plan.earlyPayUrl ? ( {t('early_pay')} ) : null} ) : null} {t('due_dates')} {plan.installments.map((row) => ( ))} {/* Ownership note: Balinyaar displays, it does not manage, this provider-owned schedule. */} {t('provider_owned_note', { provider: providerName })} ); } export default WalletInstallments;