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 { 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, withCtx } from "vue";
import { Calendar } from "@lucide/vue";
//#region src/components/compositions/elements/picker/DatePicker.vue?vue&type=script&setup=true&lang.ts
var DatePicker_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
	__name: "DatePicker",
	props: /* @__PURE__ */ mergeModels({
		modelValue: {},
		id: {},
		name: {},
		label: {},
		hideLabel: { type: Boolean },
		placeholder: {},
		required: { type: Boolean },
		readonly: { type: Boolean },
		disabled: { type: Boolean },
		helpText: {},
		errors: { default: () => [] },
		minDate: {},
		maxDate: {},
		format: {}
	}, {
		"modelValue": {},
		"modelModifiers": {}
	}),
	emits: ["update:modelValue"],
	setup(__props) {
		/**
		* Props-driven date picker composition. Popover trigger Button shows the
		* formatted current date; the popover hosts the shadcn `Calendar`.
		* Values round-trip as ISO date strings (`yyyy-MM-dd` by default).
		*
		*   <DatePicker v-model="startsAt" label="Starts at" />
		*
		* Self-contained — no Pinia / store coupling. Composes `FieldFrame` for
		* label / helpText / errors chrome.
		*/
		const props = __props;
		const model = useModel(__props, "modelValue");
		const open = ref(false);
		const calendarValue = computed(() => {
			const iso = model.value;
			if (!iso) return;
			return safeParseDate(iso);
		});
		const min = computed(() => props.minDate ? safeParseDate(props.minDate) : void 0);
		const max = computed(() => props.maxDate ? safeParseDate(props.maxDate) : void 0);
		const displayValue = computed(() => {
			const iso = model.value;
			if (!iso) return "";
			return formatDate(iso, props.format);
		});
		function safeParseDate(value) {
			try {
				return $58246871e4652552$export$6b862160d295c8e(value.includes("T") ? value.slice(0, 10) : value);
			} catch {
				return;
			}
		}
		function formatDate(iso, format) {
			const parsed = safeParseDate(iso);
			if (!parsed) return iso;
			if (!format || format === "yyyy-MM-dd") return parsed.toString();
			const date = new Date(parsed.year, parsed.month - 1, parsed.day);
			try {
				return new Intl.DateTimeFormat(void 0, {
					year: "numeric",
					month: "short",
					day: "2-digit"
				}).format(date);
			} catch {
				return parsed.toString();
			}
		}
		function onSelect(value) {
			if (!value) {
				model.value = null;
				return;
			}
			model.value = (value instanceof $2aaf608024c21ca1$export$99faa760c7908e4f ? value : new $2aaf608024c21ca1$export$99faa760c7908e4f(value.year, value.month, value.day)).toString();
			open.value = false;
		}
		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", !model.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"), 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,
							"min-value": min.value,
							"max-value": max.value,
							placeholder: calendarValue.value ?? min.value ?? max.value,
							"onUpdate:modelValue": onSelect
						}, null, 8, [
							"model-value",
							"min-value",
							"max-value",
							"placeholder"
						])]),
						_: 1
					})]),
					_: 1
				}, 8, ["open"])]),
				_: 1
			}, 8, [
				"label",
				"required",
				"hide-label",
				"for",
				"help-text",
				"errors"
			]);
		};
	}
});
//#endregion
//#region src/components/compositions/elements/picker/DatePicker.vue
var DatePicker_exports = /* @__PURE__ */ __exportAll({ default: () => DatePicker_default });
var DatePicker_default = DatePicker_vue_vue_type_script_setup_true_lang_default;
//#endregion
export { DatePicker_exports as n, DatePicker_default as t };

//# sourceMappingURL=DatePicker-DCgG5oNZ.js.map