/**
 * 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_devtools = require('../../global/js/utils/devtools.js');
const require_util = require('./utils/util.js');
const require_ConditionBuilderProvider = require('./ConditionBuilderContext/ConditionBuilderProvider.js');
const require_handleKeyboardEvents = require('./utils/handleKeyboardEvents.js');
const require_ConditionBuilderContent = require('./ConditionBuilderContent/ConditionBuilderContent.js');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");

//#region src/components/ConditionBuilder/ConditionBuilder.tsx
/**
* Copyright IBM Corp. 2024, 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.
*/
/**@ts-ignore */
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const componentName = "ConditionBuilder";
/**
* TODO: A description of the component.
*/
const ConditionBuilder = react.default.forwardRef(({ className, inputConfig, startConditionLabel = "Add Condition", popOverSearchThreshold, getOptions, initialState, getConditionState, getActionsState, variant = require_util.NON_HIERARCHICAL_VARIANT, actions, translateWithId, statementConfigCustom, onAddItem, readOnly, ...rest }, ref) => {
	const localRef = (0, react.useRef)(null);
	const conditionBuilderRef = ref || localRef;
	const handleKeyDownHandler = (evt) => {
		require_handleKeyboardEvents.handleKeyDown(evt, conditionBuilderRef, variant);
	};
	return /* @__PURE__ */ react.default.createElement(require_ConditionBuilderProvider.ConditionBuilderProvider, {
		inputConfig,
		popOverSearchThreshold,
		getOptions,
		variant,
		translateWithId,
		conditionBuilderRef,
		statementConfigCustom,
		onAddItem,
		readOnly: !!readOnly
	}, /* @__PURE__ */ react.default.createElement("div", {
		...rest,
		className: (0, import_classnames.default)(require_util.blockClass, className, { [`${require_util.blockClass}__readonly`]: readOnly }, {}),
		ref: conditionBuilderRef,
		...require_devtools.getDevtoolsProps(componentName)
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.VStack, {
		className: `${require_util.blockClass}__${variant}`,
		onKeyDown: handleKeyDownHandler
	}, /* @__PURE__ */ react.default.createElement(require_ConditionBuilderContent.default, {
		startConditionLabel,
		getConditionState,
		getActionsState,
		initialState,
		actions
	}))));
});
ConditionBuilder.displayName = componentName;
ConditionBuilder.propTypes = {
	actions: prop_types.default.arrayOf(prop_types.default.shape({
		id: prop_types.default.oneOfType([prop_types.default.string, prop_types.default.number]).isRequired,
		label: prop_types.default.string.isRequired
	})),
	className: prop_types.default.string,
	getActionsState: prop_types.default.func,
	getConditionState: prop_types.default.func.isRequired,
	getOptions: prop_types.default.func,
	initialState: prop_types.default.shape({
		state: prop_types.default.shape({
			groups: prop_types.default.arrayOf(prop_types.default.shape({
				groupOperator: prop_types.default.string,
				statement: prop_types.default.string,
				conditions: prop_types.default.arrayOf(prop_types.default.oneOfType([prop_types.default.shape({
					property: prop_types.default.string,
					operator: prop_types.default.string,
					value: prop_types.default.oneOfType([
						prop_types.default.string,
						prop_types.default.arrayOf(prop_types.default.shape({
							id: prop_types.default.string,
							label: prop_types.default.string
						})),
						prop_types.default.shape({
							id: prop_types.default.string,
							label: prop_types.default.string
						})
					])
				}), prop_types.default.object]))
			})),
			operator: prop_types.default.string
		}),
		enabledDefault: prop_types.default.bool
	}),
	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]),
		type: prop_types.default.oneOf([
			"text",
			"textarea",
			"number",
			"date",
			"option",
			"time",
			"custom"
		]).isRequired,
		description: prop_types.default.string,
		getIsDisabled: prop_types.default.func,
		getIsHidden: prop_types.default.func,
		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
			})),
			valueFormatter: prop_types.default.func
		})
	})) }).isRequired,
	onAddItem: prop_types.default.func,
	popOverSearchThreshold: prop_types.default.number.isRequired,
	readOnly: prop_types.default.bool,
	startConditionLabel: prop_types.default.string,
	statementConfigCustom: prop_types.default.arrayOf(prop_types.default.shape({
		id: prop_types.default.string.isRequired,
		connector: prop_types.default.oneOf(["and", "or"]).isRequired,
		label: prop_types.default.string.isRequired,
		secondaryLabel: prop_types.default.string
	})),
	translateWithId: prop_types.default.func,
	variant: prop_types.default.oneOf(["Non-Hierarchical", "Hierarchical"])
};

//#endregion
exports.ConditionBuilder = ConditionBuilder;