import { useTranslation } from "react-i18next"; import type { ColumnMapping, AmountMode } from "../../shared/types"; import { clearMappingForMode } from "../../utils/importFormat"; interface ColumnMappingEditorProps { headers: string[]; mapping: ColumnMapping; amountMode: AmountMode; onMappingChange: (mapping: ColumnMapping) => void; /** * The mode carries the pruned mapping with it. Both have to land in a single * state update: the parent's handlers each spread the same `config` prop, so * two consecutive calls would see the same stale value and the second would * overwrite the first. */ onAmountModeChange: (mode: AmountMode, mapping: ColumnMapping) => void; } export default function ColumnMappingEditor({ headers, mapping, amountMode, onMappingChange, onAmountModeChange, }: ColumnMappingEditorProps) { const { t } = useTranslation(); // The mode is the source of truth for the mapping, not the reverse: leaving a // mode drops its columns so a stale key cannot keep deciding how amounts are // read (#324). const selectMode = (mode: AmountMode) => onAmountModeChange(mode, clearMappingForMode(mapping, mode)); const columnOptions = headers.map((h, i) => ( )); const selectClass = "w-full px-3 py-2 text-sm rounded-lg border border-[var(--border)] bg-[var(--card)] text-[var(--foreground)] focus:outline-none focus:ring-2 focus:ring-[var(--primary)]"; return (

{t("import.config.columnMapping")}

{amountMode === "single" ? (
) : (
)}
); }