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

require("../../../_virtual/_rolldown/runtime.js");
let react = require("react");
//#region src/components/DataSpreadsheet/hooks/useMoveActiveCell.js
/**
* Copyright IBM Corp. 2022, 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 useMoveActiveCell = ({ spreadsheetRef, activeCellCoordinates, containerHasFocus, createActiveCell, activeCellContent, isActiveHeaderCellChanged }) => {
	let performCreateActiveCell;
	(0, react.useEffect)(() => {
		performCreateActiveCell();
	}, [
		activeCellContent,
		performCreateActiveCell,
		isActiveHeaderCellChanged
	]);
	performCreateActiveCell = (0, react.useCallback)(() => {
		const activeCellPlacementElement = spreadsheetRef?.current.querySelector(`[data-row-index="${activeCellCoordinates?.row}"][data-column-index="${activeCellCoordinates?.column}"]`);
		const shouldPlaceActiveCellInHeader = activeCellCoordinates?.row === "header" && true;
		const selectAllElement = spreadsheetRef?.current.querySelector(`[data-row-index="header"][data-column-index="header"]`);
		if (containerHasFocus) createActiveCell({
			placementElement: activeCellCoordinates ? activeCellPlacementElement : selectAllElement,
			coords: activeCellCoordinates,
			addToHeader: shouldPlaceActiveCellInHeader
		});
	}, [
		spreadsheetRef,
		activeCellCoordinates,
		containerHasFocus,
		createActiveCell
	]);
};
//#endregion
exports.useMoveActiveCell = useMoveActiveCell;
