/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

//#region src/components/Datagrid/Datagrid/addons/Filtering/handleCheckboxChange.js
/**
* Copyright IBM Corp. 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const handleCheckboxChange = ({ checked, filtersState, column, option, setFiltersState, applyFilters, type }) => {
	const checkboxCopy = filtersState[column].value;
	const foundCheckbox = checkboxCopy.find((checkbox) => checkbox.value === option.value);
	foundCheckbox.selected = checked;
	setFiltersState({
		...filtersState,
		[column]: {
			value: checkboxCopy,
			type
		}
	});
	applyFilters({
		column,
		value: [...filtersState[column].value],
		type
	});
	option.onChange?.(checked);
};
//#endregion
export { handleCheckboxChange };
