/**
 * 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.
 */

const require_runtime = require('../../_virtual/_rolldown/runtime.js');
const require_debounce = require('../../global/js/utils/debounce.js');
let react = require("react");

//#region src/components/Datagrid/useRowIsMouseOver.ts
/**
* Copyright IBM Corp. 2024, 2025
*
* 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 useRowIsMouseOver = (hooks) => {
	const useInstance = (instance) => {
		const [mouseOverRowIndex, setMouseOverRowIndex] = (0, react.useState)();
		const onMouseChange = useDebounce((datagridState) => {
			const { row } = datagridState;
			setMouseOverRowIndex(row?.index);
		}, 100);
		const getRowProps = (props, datagridState) => {
			const onMouseOver = () => onMouseChange(datagridState);
			return [props, { onMouseOver }];
		};
		const { rows } = instance;
		const rowsWithMouseOver = rows.map((row) => ({
			...row,
			isMouseOver: row.index === mouseOverRowIndex
		}));
		Object.assign(instance, {
			rows: rowsWithMouseOver,
			withMouseHover: true,
			setMouseOverRowIndex
		});
		hooks.getRowProps.push(getRowProps);
	};
	hooks.useInstance.push(useInstance);
};
const useDebounce = (fn, wait) => (0, react.useCallback)(require_debounce.debounce(fn, wait), []);

//#endregion
exports.default = useRowIsMouseOver;