import { useTranslation } from 'react-i18next'; import { DEFAULT_PREHEAT_FILAMENT_TARGETS, PREHEAT_FILAMENT_ORDER, parsePreheatFilamentTargets, serializePreheatFilamentTargets, } from '../utils/preheatFilamentTargets'; import { MAX_CHAMBER_TEMP_C } from '../utils/printer'; interface Props { // JSON-encoded map; empty string means "use bundled defaults". value: string; onChange: (next: string) => void; disabled?: boolean; } // Per-filament chamber target editor for Settings → Workflow → Preheat card // (#1468). Renders one row per filament type with a numeric input clamped to // 0-MAX_CHAMBER_TEMP_C. Stripping back to the bundled defaults is handled by the parent // (Reset button next to the section title) — passing an empty string upward // is the canonical "use defaults" signal, which keeps the editor stateless // across resets. export function PreheatFilamentTargetsEditor({ value, onChange, disabled = false }: Props) { const { t } = useTranslation(); const map = parsePreheatFilamentTargets(value); const updateOne = (key: string, next: number) => { const clamped = Math.max(0, Math.min(MAX_CHAMBER_TEMP_C, Math.round(next))); const updated = { ...map, [key]: clamped }; onChange(serializePreheatFilamentTargets(updated)); }; return (
{PREHEAT_FILAMENT_ORDER.map((key) => { const current = map[key] ?? DEFAULT_PREHEAT_FILAMENT_TARGETS[key] ?? 0; const label = key === 'default' ? t('settings.preheatFilamentTargetsDefaultRow', 'Other / unmapped') : key; return (
{label}
updateOne(key, parseInt(e.target.value, 10) || 0)} disabled={disabled} className="w-16 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs text-right focus:outline-none focus:border-bambu-green disabled:opacity-50" /> °C
); })}
); }