/**
 * 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_index = require('../../node_modules/classnames/index.js');
const require_settings = require('../../settings.js');
const require_InlineEditCell = require('./Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js');
let react = require("react");
react = require_runtime.__toESM(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__ */ require_runtime.__toESM(require_index.default);
const blockClass = `${require_settings.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.default.createElement(require_InlineEditCell.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.default.createElement(react.default.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.default.createElement(require_InlineEditCell.InlineEditCell, {
				config: columnInlineEditConfig,
				tabIndex: -1,
				value: cell.value?.value,
				cell,
				instance,
				nonEditCell: true,
				type: "text"
			}), !inlineEditType && /* @__PURE__ */ react.default.createElement(require_InlineEditCell.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
exports.default = useInlineEdit;