import { cn } from '@/lib/utils';
import { resolveOption } from '../protocol';
import { ActionButton } from './ActionButton';
import { StepButton, type ControlInternalProps } from './shared';
const INCREMENTAL_STEP_GRID = 'grid-cols-[46px_minmax(0,1fr)_46px]';
export const IncrementalControl = ({ cheat, value, disabled, onChange }: ControlInternalProps) => {
const options = (cheat.args.options ?? []).map(resolveOption);
if (options.length === 0) {
return ;
}
const currentIndex = options.findIndex((option) => isSameOption(option.value, value));
const previous = currentIndex > 0 ? options[currentIndex - 1] : null;
const next = currentIndex >= 0 && currentIndex < options.length - 1 ? options[currentIndex + 1] : null;
const currentLabel = options[currentIndex]?.label ?? String(value ?? '--');
return (
previous && onChange(previous.value)} />
{currentLabel}{cheat.args.postfix ?? ''}
next && onChange(next.value)} />
);
};
function isSameOption(left: unknown, right: unknown): boolean {
return String(left) === String(right);
}