import { n as __exportAll } from "./chunk-B-1-B7_t.js";
import { n as cn } from "./utils-DXzSsU1e.js";
import { n as Button_default } from "./button-B9CnnuTu.js";
import { f as Calendar_default } from "./calendar-CU8pgFN5.js";
import { t as Input_default } from "./input-CwDp-vE8.js";
import { n as PopoverContent_default, s as Popover_default, t as PopoverTrigger_default } from "./popover-B67tUcQt.js";
import { t as FieldFrame_default } from "./field-frame-DhCOWcMP.js";
import { n as $58246871e4652552$export$6b862160d295c8e, t as $2aaf608024c21ca1$export$99faa760c7908e4f } from "./CalendarDate-C38xoKyL.js";
import { computed, createBlock, createElementVNode, createVNode, defineComponent, mergeModels, normalizeClass, openBlock, ref, toDisplayString, unref, useModel, watchEffect, withCtx } from "vue";
import { Calendar, Clock } from "@lucide/vue";
//#region src/components/compositions/elements/picker/DateTimePicker.vue?vue&type=script&setup=true&lang.ts
var _hoisted_1 = { class: "flex items-center gap-2 border-t p-3" };
var DateTimePicker_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "DateTimePicker",
	props: /* @__PURE__ */ mergeModels({
		modelValue: {},
		id: {},
		name: {},
		label: {},
		hideLabel: { type: Boolean },
		placeholder: {},
		required: { type: Boolean },
		readonly: { type: Boolean },
		disabled: { type: Boolean },
		helpText: {},
		errors: { default: () => [] }
	}, {
		"modelValue": {},
		"modelModifiers": {}
	}),
	emits: ["update:modelValue"],
	setup(__props) {
		/**
		* Props-driven date+time picker composition. DatePicker-style Popover
		* (Calendar) plus two numeric inputs for hour/minute. Round-trips ISO
		* 8601 (e.g. `2024-06-15T13:30:00`). When only the date half is set the
		* value falls back to a date-only ISO string.
		*
		*   <DateTimePicker v-model="when" label="Starts at" />
		*/
		const model = useModel(__props, "modelValue");
		const datePart = ref("");
		const hourPart = ref("");
		const minutePart = ref("");
		watchEffect(() => {
			const iso = model.value;
			if (!iso) {
				datePart.value = "";
				hourPart.value = "";
				minutePart.value = "";
				return;
			}
			const [d, t] = iso.split("T");
			datePart.value = d ?? "";
			if (t) {
				const [hh, mm] = t.split(":");
				hourPart.value = hh ?? "";
				minutePart.value = (mm ?? "").slice(0, 2);
			} else {
				hourPart.value = "";
				minutePart.value = "";
			}
		});
		const open = ref(false);
		const calendarValue = computed(() => {
			if (!datePart.value) return;
			try {
				return $58246871e4652552$export$6b862160d295c8e(datePart.value);
			} catch {
				return;
			}
		});
		function emitCombined() {
			if (!datePart.value) {
				model.value = null;
				return;
			}
			if (hourPart.value === "" && minutePart.value === "") {
				model.value = datePart.value;
				return;
			}
			const hh = padTwo(hourPart.value || "0");
			const mm = padTwo(minutePart.value || "0");
			model.value = `${datePart.value}T${hh}:${mm}:00`;
		}
		function padTwo(value) {
			return Math.max(0, parseInt(value, 10) || 0).toString().padStart(2, "0");
		}
		function onDateSelected(value) {
			if (!value) {
				datePart.value = "";
				emitCombined();
				return;
			}
			datePart.value = (value instanceof $2aaf608024c21ca1$export$99faa760c7908e4f ? value : new $2aaf608024c21ca1$export$99faa760c7908e4f(value.year, value.month, value.day)).toString();
			emitCombined();
			open.value = false;
		}
		function onHourInput(value) {
			hourPart.value = Math.min(23, Math.max(0, parseInt(String(value ?? ""), 10) || 0)).toString();
			emitCombined();
		}
		function onMinuteInput(value) {
			minutePart.value = Math.min(59, Math.max(0, parseInt(String(value ?? ""), 10) || 0)).toString();
			emitCombined();
		}
		const displayValue = computed(() => {
			if (!datePart.value) return "";
			if (hourPart.value === "" && minutePart.value === "") return datePart.value;
			return `${datePart.value} ${padTwo(hourPart.value || "0")}:${padTwo(minutePart.value || "0")}`;
		});
		return (_ctx, _cache) => {
			return openBlock(), createBlock(unref(FieldFrame_default), {
				label: __props.label,
				required: __props.required,
				"hide-label": __props.hideLabel,
				for: __props.id,
				"help-text": __props.helpText,
				errors: __props.errors
			}, {
				default: withCtx(() => [createVNode(unref(Popover_default), {
					open: open.value,
					"onUpdate:open": _cache[0] || (_cache[0] = ($event) => open.value = $event)
				}, {
					default: withCtx(() => [createVNode(unref(PopoverTrigger_default), { "as-child": "" }, {
						default: withCtx(() => [createVNode(unref(Button_default), {
							type: "button",
							variant: "outline",
							disabled: __props.disabled,
							class: normalizeClass(unref(cn)("w-full justify-start text-left font-normal", !displayValue.value && "text-muted-foreground")),
							"data-element-name": __props.name ?? void 0,
							"data-readonly": __props.readonly || void 0
						}, {
							default: withCtx(() => [createVNode(unref(Calendar), { class: "mr-2 size-4" }), createElementVNode("span", null, toDisplayString(displayValue.value || __props.placeholder || "Pick a date & time"), 1)]),
							_: 1
						}, 8, [
							"disabled",
							"class",
							"data-element-name",
							"data-readonly"
						])]),
						_: 1
					}), createVNode(unref(PopoverContent_default), { class: "w-auto p-0" }, {
						default: withCtx(() => [createVNode(unref(Calendar_default), {
							"model-value": calendarValue.value,
							placeholder: calendarValue.value,
							"onUpdate:modelValue": onDateSelected
						}, null, 8, ["model-value", "placeholder"]), createElementVNode("div", _hoisted_1, [
							createVNode(unref(Clock), { class: "size-4 text-muted-foreground" }),
							createVNode(unref(Input_default), {
								type: "number",
								min: "0",
								max: "23",
								"model-value": hourPart.value,
								class: "w-16",
								disabled: __props.disabled,
								placeholder: "HH",
								"data-testid": "datetime-hour",
								"onUpdate:modelValue": onHourInput
							}, null, 8, ["model-value", "disabled"]),
							_cache[1] || (_cache[1] = createElementVNode("span", { class: "text-muted-foreground" }, ":", -1)),
							createVNode(unref(Input_default), {
								type: "number",
								min: "0",
								max: "59",
								"model-value": minutePart.value,
								class: "w-16",
								disabled: __props.disabled,
								placeholder: "MM",
								"data-testid": "datetime-minute",
								"onUpdate:modelValue": onMinuteInput
							}, null, 8, ["model-value", "disabled"])
						])]),
						_: 1
					})]),
					_: 1
				}, 8, ["open"])]),
				_: 1
			}, 8, [
				"label",
				"required",
				"hide-label",
				"for",
				"help-text",
				"errors"
			]);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/picker/DateTimePicker.vue
var DateTimePicker_exports = /* @__PURE__ */ __exportAll({ default: () => DateTimePicker_default });
var DateTimePicker_default = DateTimePicker_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { DateTimePicker_exports as n, DateTimePicker_default as t };

//# sourceMappingURL=DateTimePicker-CQySj3IG.js.map