/**
 * 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,
		onRemoveItem: props.onRemoveItem,
		readOnly: props.readOnly
	};
	return /* @__PURE__ */ react.default.createElement(ConditionBuilderContext.Provider, { value: contextValue }, props.children);
};
ConditionBuilderProvider.propTypes = {
	/**
	* Provide the contents of the ConditionBuilder.
	*/
	children: prop_types.default.node.isRequired,
	/**
	* ref of condition builder
	*/
	/**@ts-ignore */
	conditionBuilderRef: prop_types.default.object,
	/**
	* This is an optional callback function that will be triggered when options array is not passed in the inputConfig against a property. 
	* This can be a asynchronous function that need  to  return a promise, so it will allow to fetch options from API call.
	* options has to be in valid format
	* [{
	label: 'label',
	id: 'id',
	},...] 
	*/
	getOptions: prop_types.default.func,
	/**
	* This is a mandatory prop that defines the input to the condition builder.
	
	*/
	/**@ts-ignore */
	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,
	/**
	* This will enable search in option popovers when option list length is more that this threshold
	*/
	popOverSearchThreshold: prop_types.default.number.isRequired,
	/**
	* Optional prop if you want to pass translation to the texts used . Otherwise this will the defined defaults.
	* This callback function will receive the message id and you need to return the corresponding text for that id.
	* The message key will be one of [   "ifText",   "addConditionText",   "addConditionGroupText",   "addSubgroupText",   "conditionText",   "propertyText",   "operatorText",   "valueText",   "connectorText",   "conditionRowText",   "removeConditionText",   "addConditionRowText",   "startText",   "endText",   "clearSearchText",   "actionsText",   "then",   "removeActionText",   "addActionText",   "invalidText",   "invalidNumberWarnText"
	]
	*/
	translateWithId: prop_types.default.func,
	/**
	* Provide the condition builder variant: Non-Hierarchical/ Hierarchical
	*/
	variant: prop_types.default.string.isRequired
};
//#endregion
exports.ConditionBuilderContext = ConditionBuilderContext;
exports.ConditionBuilderProvider = ConditionBuilderProvider;
exports.getEmptyState = getEmptyState;
