/**
 * 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_uuidv4 = require('../../../global/js/utils/uuidv4.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/ConditionBuilder/ConditionBuilderContext/ConditionBuilderProvider.tsx
/**
* Copyright IBM Corp. 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 getEmptyState = (statementConfigCustom) => {
	const defaultStatement = statementConfigCustom?.[0];
	const defaultStatementId = defaultStatement?.id ?? "ifAll";
	return {
		operator: "or",
		groups: [{
			groupOperator: defaultStatement?.connector ?? "and",
			statement: defaultStatementId,
			id: require_uuidv4.default(),
			conditions: [{
				property: void 0,
				operator: "",
				value: "",
				popoverToOpen: "propertyField",
				id: require_uuidv4.default()
			}]
		}]
	};
};
const ConditionBuilderContext = (0, react.createContext)({
	rootState: { groups: [] },
	popOverSearchThreshold: 0
});
const ConditionBuilderProvider = (props) => {
	const [rootState, setRootState] = (0, react.useState)({ groups: [] });
	const [actionState, setActionState] = (0, react.useState)([]);
	const contextValue = {
		rootState,
		setRootState,
		actionState,
		setActionState,
		inputConfig: props.inputConfig,
		popOverSearchThreshold: props.popOverSearchThreshold,
		getOptions: props.getOptions,
		variant: props.variant,
		translateWithId: props.translateWithId,
		conditionBuilderRef: props.conditionBuilderRef,
		statementConfigCustom: props.statementConfigCustom,
		onAddItem: props.onAddItem,
		readOnly: props.readOnly
	};
	return /* @__PURE__ */ react.default.createElement(ConditionBuilderContext.Provider, { value: contextValue }, props.children);
};
ConditionBuilderProvider.propTypes = {
	children: prop_types.default.node.isRequired,
	conditionBuilderRef: prop_types.default.object,
	getOptions: prop_types.default.func,
	inputConfig: prop_types.default.shape({ properties: prop_types.default.arrayOf(prop_types.default.shape({
		id: prop_types.default.string.isRequired,
		label: prop_types.default.string.isRequired,
		icon: prop_types.default.oneOfType([prop_types.default.func, prop_types.default.object]),
		description: prop_types.default.string,
		type: prop_types.default.oneOf([
			"text",
			"textarea",
			"number",
			"date",
			"option",
			"time",
			"custom"
		]).isRequired,
		config: prop_types.default.shape({
			options: prop_types.default.arrayOf(prop_types.default.shape({
				id: prop_types.default.string.isRequired,
				label: prop_types.default.string.isRequired,
				icon: prop_types.default.oneOfType([prop_types.default.func, prop_types.default.object])
			})),
			component: prop_types.default.func,
			operators: prop_types.default.arrayOf(prop_types.default.shape({
				id: prop_types.default.string.isRequired,
				label: prop_types.default.string.isRequired
			})),
			long: prop_types.default.bool
		})
	})) }).isRequired,
	popOverSearchThreshold: prop_types.default.number.isRequired,
	translateWithId: prop_types.default.func,
	variant: prop_types.default.string.isRequired
};

//#endregion
exports.ConditionBuilderContext = ConditionBuilderContext;
exports.ConditionBuilderProvider = ConditionBuilderProvider;
exports.getEmptyState = getEmptyState;