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

import RowSizeDropdown from "./Datagrid/addons/RowSize/RowSizeDropdown.js";
import { useState } from "react";
//#region src/components/Datagrid/useRowSize.js
/**
* 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 useRowSize = (hooks) => {
	const [internalRowSize, setRowSize] = useState("");
	hooks.useInstance.push((instance) => {
		const { rowSizeProps, rowSizes, rowSize, onRowSizeChange, tableId } = instance;
		const { labels } = rowSizeProps || {};
		Object.assign(instance, {
			rowSize: internalRowSize || rowSize,
			rowSizeDropdownProps: {
				rowSizes,
				...labels,
				selectedOption: internalRowSize || rowSize,
				onChange: (value) => {
					setRowSize(value);
					if (typeof onRowSizeChange === "function") onRowSizeChange(value);
				},
				tableId
			},
			RowSizeDropdown
		});
	});
	const getTableProps = (props, { instance }) => {
		const { rowSize } = instance;
		if (!rowSize) return props;
		return [props, { size: rowSize }];
	};
	hooks.getTableProps.push(getTableProps);
};
//#endregion
export { useRowSize as default };
