/**
 * 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 { __toESM } from "../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../node_modules/classnames/index.js";
import { pkg } from "../../settings.js";
import { InlineEditCell } from "./Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js";
import React from "react";
//#region src/components/Datagrid/useInlineEdit.tsx
/**
* 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.
*/
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--datagrid`;
const useInlineEdit = (hooks) => {
	const addInlineEdit = (props, { cell, instance }) => {
		const columnInlineEditConfig = cell.column.inlineEdit;
		const inlineEditType = cell.column?.inlineEdit?.type;
		const isDisabled = cell.column?.isDisabled;
		const staticCell = typeof cell.value === "object" && cell.column.id === cell.value?.columnId && cell.value?.isStaticCell;
		const renderInlineEditComponent = (type) => /* @__PURE__ */ React.createElement(InlineEditCell, {
			config: columnInlineEditConfig,
			tabIndex: -1,
			value: cell.value,
			cell,
			disabledCell: isDisabled,
			instance,
			type
		});
		if (cell.column.id === "spacer") return [props, { className: (0, import_classnames.default)(`${blockClass}__cell`, `${blockClass}__cell--spacer`) }];
		return [props, {
			className: (0, import_classnames.default)(`${blockClass}__cell`, `${blockClass}__cell-inline-edit`),
			role: "gridcell",
			children: /* @__PURE__ */ React.createElement(React.Fragment, null, !staticCell && inlineEditType === "text" && renderInlineEditComponent(inlineEditType), !staticCell && inlineEditType === "number" && renderInlineEditComponent(inlineEditType), !staticCell && inlineEditType === "selection" && renderInlineEditComponent(inlineEditType), inlineEditType === "checkbox" && renderInlineEditComponent(inlineEditType), !staticCell && inlineEditType === "date" && renderInlineEditComponent(inlineEditType), staticCell && /* @__PURE__ */ React.createElement(InlineEditCell, {
				config: columnInlineEditConfig,
				tabIndex: -1,
				value: cell.value?.value,
				cell,
				instance,
				nonEditCell: true,
				type: "text"
			}), !inlineEditType && /* @__PURE__ */ React.createElement(InlineEditCell, {
				config: columnInlineEditConfig,
				tabIndex: -1,
				value: cell.value,
				cell,
				instance,
				disabledCell: isDisabled,
				nonEditCell: true,
				type: "text"
			}))
		}];
	};
	hooks.getCellProps.push(addInlineEdit);
	hooks.useInstance.push((instance) => {
		Object.assign(instance, { withInlineEdit: true });
	});
};
//#endregion
export { useInlineEdit as default };
