/**
 * 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_DatagridExpandedRow = require('./Datagrid/DatagridExpandedRow.js');
const require_useRowExpander = require('./useRowExpander.js');
let react = require("react");

//#region src/components/Datagrid/useExpandedRow.ts
/**
* Copyright IBM Corp. 2020, 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 useExpandedRow = (hooks) => {
	require_useRowExpander.default(hooks);
	const useInstance = (instance) => {
		const { rows, expandedContentHeight, ExpandedRowContentComponent, onRowExpand } = instance;
		const [expandedRowsHeight, setExpandedRowsHeight] = (0, react.useState)({});
		const setExpandedRowHeight = (rowIndex, height) => setExpandedRowsHeight({
			...expandedRowsHeight,
			[rowIndex]: height
		});
		const rowsWithExpand = rows.map((row) => ({
			...row,
			canExpand: row.original && !row.original.notExpandable,
			expandedContentHeight: expandedRowsHeight[row.index] || expandedContentHeight,
			RowExpansionRenderer: ExpandedRowContentComponent && require_DatagridExpandedRow.default(ExpandedRowContentComponent),
			onClick: (row, event) => onRowExpand?.(row, event)
		}));
		Object.assign(instance, {
			rows: rowsWithExpand,
			setExpandedRowHeight,
			withExpandedRows: true
		});
	};
	hooks.useInstance.push(useInstance);
};

//#endregion
exports.default = useExpandedRow;