import React from 'react'; import type { ShippingRate, LocationType } from '@/types/shipping.types'; interface RateTableProps { rates: ShippingRate[]; isLoading: boolean; onEdit: (rate: ShippingRate) => void; onDelete: (id: number) => void; isDeleting: boolean; } const LOCATION_TYPE_LABELS: Record = { province: 'Province', district: 'District', ward: 'Ward', region: 'Region', }; const WEIGHT_CALC_LABELS: Record = { replace: 'Replace', per_kg: 'Per kg', }; const fmtVND = (n: number) => new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(n); export const RateTable: React.FC = ({ rates, isLoading, onEdit, onDelete, isDeleting, }) => { if (isLoading) return

Loading...

; if (rates.length === 0) { return (

No shipping rates for this location yet.

); } return ( {rates.map((rate) => ( ))}
Location Base rate Weight calc Weight tiers Order conditions Priority Actions
{rate.location_name || rate.location_code}
{LOCATION_TYPE_LABELS[rate.location_type]}
{fmtVND(rate.base_rate)} {WEIGHT_CALC_LABELS[rate.weight_calc_type] ?? rate.weight_calc_type} {rate.weight_tiers && rate.weight_tiers.length > 0 ? (
    {rate.weight_tiers.map((tier, idx) => (
  • {tier.min}–{tier.max > 0 ? `${tier.max}` : '∞'} kg:{' '} {fmtVND(tier.price)} {rate.weight_calc_type === 'per_kg' && '/kg'}
  • ))}
) : ( )}
{rate.order_total_rules && rate.order_total_rules.length > 0 ? (
    {rate.order_total_rules.map((rule, idx) => (
  • {fmtVND(rule.min_total)} {rule.max_total > 0 ? `–${fmtVND(rule.max_total)}` : '+'}:{' '} {rule.shipping_fee === 0 ? ( Free ) : ( fmtVND(rule.shipping_fee) )}
  • ))}
) : ( )}
{rate.priority}
); };