'use client'; import { FunctionComponent } from 'react'; import { useLocale, useTranslations } from 'next-intl'; import { Divider, Paper, Stack, Typography } from '@mui/material'; import PriceBreakdown from '@/components/PriceBreakdown'; import StatusChip from '@/components/StatusChip'; import AppAlert from '@/components/common/AppAlert'; import AppIcon from '@/components/common/AppIcon'; import RefundEtaBanner from '@/components/RefundEtaBanner'; import { CANCELLATION_LEAD_HOURS } from '@/constants'; import { formatShamsiDate } from '@/utils'; import type { CancellationPolicyPreview } from '@/services/refunds/types'; export interface CancellationPolicyDisclosureProps { preview: CancellationPolicyPreview; } /** Rounds an already-0–100 percent value for display — a small display number, never money, so JS math is * safe. Never re-multiply by 100: the server (and the mock) already serve this scale. */ function toPercent(percent: number): number { return Math.round(percent); } /** * The pre-confirm cancellation disclosure (f10) — the whole point of the cancel screen: the applicable * policy tier (label off the `cancellation_policy_code` i18n key, never the raw code), the **refund % + fee * %**, the concrete refund-vs-fee split (reusing `PriceBreakdown`, which reconciles to the rial), the * multi-session refundable/locked breakdown, the admin-approved reality, and a per-channel ETA preview * (BNPL surfaces the ~7–10-day window honestly). Display-only — the reason field, acknowledgement and * confirm live in the page; shared so the confirm dialog and any future per-session cancel reuse it. * @component CancellationPolicyDisclosure */ const CancellationPolicyDisclosure: FunctionComponent = ({ preview }) => { const t = useTranslations('refunds'); const locale = useLocale(); const refundPercent = toPercent(preview.refundPercentageApplied); const feePercent = toPercent(preview.feePercentage); const isMultiSession = preview.sessions.length > 1; return ( {t(`policy_${preview.cancellationPolicyCode}`)} 0 ? 'active' : 'rejected'} label={t('refund_percent', { percent: refundPercent })} /> {t(`lead_${preview.leadTimeLabel}`, { hours: CANCELLATION_LEAD_HOURS })} {t('fee_percent', { percent: feePercent })} {isMultiSession && ( {t('sessions_title')} {preview.sessions.map((session) => ( {`${session.sessionIndex}. ${formatShamsiDate(session.scheduledDate, locale)}`} ))} )} } data-testid="admin-approval-explainer" sx={{ marginY: 0 }} > {t('admin_approval_explainer')} ); }; export default CancellationPolicyDisclosure;