import { produce } from 'immer';
import { useCallback } from 'react';
/**
 * Creates a callback handler for changing the step based on a dropdown value.
 * This only handles basic cases where the dropdown option key can be set on the
 * step using an object path.
 */ export function useDropdownChangeHandler(step, updateFn, onChange) {
    /* eslint-disable-next-line react-hooks/exhaustive-deps */ return useCallback(getDropdownChangeHandler(step, updateFn, onChange), [
        step,
        onChange,
        updateFn, 
    ]);
}
export function getDropdownChangeHandler(step, updateFn, onChange) {
    return (_event, option)=>{
        onChange?.(produce(step, (draft)=>{
            updateFn(draft, option?.key);
        }));
    };
}
/**
 * Creates a callback handler for changing the step based on a combobox value.
 * This only handles basic cases where the combobox option key can be set on the
 * step using an object path.
 */ export function useComboBoxChangeHandler(step, updateFn, onChange) {
    /* eslint-disable-next-line react-hooks/exhaustive-deps */ return useCallback(getComboBoxChangeHandler(step, updateFn, onChange), [
        step,
        onChange,
        updateFn, 
    ]);
}
export function getComboBoxChangeHandler(step, updateFn, onChange) {
    return (_event, option, _index, value)=>{
        onChange?.(produce(step, (draft)=>{
            updateFn(draft, option?.key, value);
        }));
    };
}
/**
 * Creates a callback handler for changing the step based on a combobox value.
 * This only handles basic cases where the combobox option key can be set on the
 * step using an object path.
 */ export function useComboBoxInputValueChangeHandler(step, updateFn, onChange) {
    /* eslint-disable-next-line react-hooks/exhaustive-deps */ return useCallback(getComboBoxInputValueChangeHandler(step, updateFn, onChange), [
        step,
        onChange,
        updateFn
    ]);
}
export function getComboBoxInputValueChangeHandler(step, updateFn, onChange) {
    return (value)=>{
        onChange?.(produce(step, (draft)=>{
            updateFn(draft, value);
        }));
    };
}
export function useTextFieldChangeHandler(step, updateFn, onChange) {
    /* eslint-disable-next-line react-hooks/exhaustive-deps */ return useCallback(getTextFieldChangeHandler(step, updateFn, onChange), [
        step,
        updateFn,
        onChange, 
    ]);
}
export function getTextFieldChangeHandler(step, updateFn, onChange) {
    return (_event, newValue)=>{
        onChange?.(produce(step, (draft)=>{
            updateFn(draft, newValue);
        }));
    };
}
/**
 * Enforces numeric values for a SpinButton onChange.
 * @param step - the step object
 * @param updateFn - the update function
 * @param onChange -the onchange handler
 * @returns
 */ export function useSpinButtonChangeHandler(step, updateFn, onChange) {
    /* eslint-disable-next-line react-hooks/exhaustive-deps */ return useCallback(getSpinButtonChangeHandler(step, updateFn, onChange), [
        step,
        onChange,
        updateFn, 
    ]);
}
export function getSpinButtonChangeHandler(step, updateFn, onChange) {
    return (_event, newValue)=>{
        onChange?.(produce(step, (draft)=>{
            updateFn(draft, newValue);
        }));
    };
}
export function useCheckboxChangeHandler(step, updateFn, onChange) {
    /* eslint-disable-next-line react-hooks/exhaustive-deps */ return useCallback(getCheckboxChangeHandler(step, updateFn, onChange), [
        step,
        updateFn,
        onChange, 
    ]);
}
export function getCheckboxChangeHandler(step, updateFn, onChange) {
    return (_event, checked)=>{
        onChange?.(produce(step, (draft)=>{
            updateFn(draft, checked);
        }));
    };
} // #endregion
