/**
 * 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_returnUpdatedActiveCell = require('./returnUpdatedActiveCell.js');
const require_getCellIdAsObject = require('./getCellIdAsObject.js');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);

//#region src/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/InlineEditContext.jsx
/**
* Copyright IBM Corp. 2022, 2022
*
* 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 InlineEditContext = (0, react.createContext)({
	state: {},
	dispatch: ({ type, payload }) => {}
});
const inlineEditReducer = (state, action) => {
	switch (action.type) {
		case "ADD_GRID_ACTIVE_FOCUS": return {
			...state,
			gridActive: true,
			activeCellId: action.payload,
			previousActiveCellId: null
		};
		case "REMOVE_GRID_ACTIVE_FOCUS": return {
			...state,
			gridActive: false,
			editId: null,
			activeCellId: null,
			previousActiveCellId: action.payload
		};
		case "ENTER_EDIT_MODE": return {
			...state,
			activeCellId: action.payload.activeCellId,
			editId: action.payload.editId
		};
		case "EXIT_EDIT_MODE": return {
			...state,
			activeCellId: action.payload,
			editId: null
		};
		case "UPDATE_ACTIVE_CELL_ID": {
			const { direction, oldId, instance } = action.payload;
			if (!action.payload.direction) return {
				...state,
				activeCellId: action.payload,
				editId: null
			};
			if (direction && typeof direction === "string") return require_returnUpdatedActiveCell.returnUpdatedActiveCell({
				activeCellCoords: require_getCellIdAsObject.getCellIdAsObject(oldId),
				direction,
				totalVisibleColumns: instance.visibleColumns.filter((item) => item.id !== "spacer"),
				state,
				instance
			});
			break;
		}
		case "SET_FEATURE_FLAGS": return {
			...state,
			featureFlags: action.payload ?? {}
		};
		default: return state;
	}
};
const InlineEditProvider = ({ children }) => {
	const [state, dispatch] = (0, react.useReducer)(inlineEditReducer, {});
	return /* @__PURE__ */ react.default.createElement(InlineEditContext.Provider, { value: {
		state,
		dispatch
	} }, children);
};
InlineEditProvider.propTypes = { children: prop_types.default.element };

//#endregion
exports.InlineEditContext = InlineEditContext;
exports.InlineEditProvider = InlineEditProvider;