/**
 * 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_util = require("../../utils/util.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/ConditionBuilderItem/ConditionBuilderItemTime/ConditionBuilderItemTime.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 ConditionBuilderItemTime = ({ onChange, config, conditionState }) => {
	const getInitialValue = (itemType) => {
		return conditionState.value !== "INVALID" ? conditionState.value?.split(" ")[{
			time: 0,
			dayZone: 1,
			timeZone: 2
		}[itemType]] ?? void 0 : void 0;
	};
	const initialTimeValue = getInitialValue("time");
	const initialDayZone = getInitialValue("dayZone");
	const initialTimeZone = getInitialValue("timeZone");
	const [timeValue, setTimeValue] = (0, react.useState)(initialTimeValue);
	const [dayZoneValue, setDayZoneValue] = (0, react.useState)(initialDayZone ?? "AM");
	const [timeZoneValue, setTimeZoneValue] = (0, react.useState)(initialTimeZone ?? config?.timeZones?.[0]);
	(0, react.useEffect)(() => {
		const timeToUpdate = `${timeValue ?? ""} ${dayZoneValue ?? ""} ${timeZoneValue ?? ""}`;
		onChange(timeValue ? timeToUpdate : "INVALID");
	}, [
		timeValue,
		dayZoneValue,
		timeZoneValue
	]);
	const setTimeZone = (evt) => {
		setTimeZoneValue(evt.target.value);
	};
	const setDayZone = (evt) => {
		setDayZoneValue(evt.target.value);
	};
	const setTime = (evt) => {
		setTimeValue(evt.target.value);
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: `${require_util.blockClass}__item-time` }, /* @__PURE__ */ react.default.createElement(_carbon_react.TimePicker, {
		defaultValue: initialTimeValue,
		id: "time-picker",
		labelText: "Select a time",
		onChange: setTime
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.TimePickerSelect, {
		id: "time-picker-day-zone",
		defaultValue: initialDayZone,
		onChange: setDayZone
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.SelectItem, {
		value: "AM",
		text: "AM"
	}), /* @__PURE__ */ react.default.createElement(_carbon_react.SelectItem, {
		value: "PM",
		text: "PM"
	})), /* @__PURE__ */ react.default.createElement(_carbon_react.TimePickerSelect, {
		id: "time-picker-time-zone",
		defaultValue: initialTimeZone,
		onChange: setTimeZone
	}, config?.timeZones?.map((timeZone, index) => /* @__PURE__ */ react.default.createElement(_carbon_react.SelectItem, {
		key: index,
		value: timeZone,
		text: timeZone
	})))));
};
ConditionBuilderItemTime.propTypes = {
	/**
	* current condition object
	*/
	conditionState: prop_types.default.object,
	/**
	* current config object that this property is part of
	*/
	config: prop_types.default.object,
	/**
	* callback to update state oin date change
	*/
	onChange: prop_types.default.func
};
//#endregion
exports.ConditionBuilderItemTime = ConditionBuilderItemTime;
