import { Tt as format } from "./connect-MjNGHHUz-BfDIyhte.js";
import { b as normalizeMonthFormat, g as getDateFormat, l as getDateFromValue, o as formatDateToValidCalendarDateFormat, t as withFieldValidation, v as isDateFormatAllowed } from "./with-field-validation-DGjBGqeq.js";
import { t as DatePicker } from "./date-picker-C1lWkDSy.js";
//#region node_modules/@powerhousedao/document-engineering/dist/src/scalars/components/date-picker-field/date-picker-validations.js
const validateDatePicker = ({ dateFormat, minDate, maxDate, disablePastDates, disableFutureDates }) => (value) => {
	if (value === "" || value === void 0) return true;
	const internalFormat = getDateFormat(dateFormat ?? "");
	const stringDate = normalizeMonthFormat(getDateFromValue(value));
	if (!isDateFormatAllowed(stringDate, internalFormat)) return "Invalid date format. Please use a valid format";
	const [datePart] = formatDateToValidCalendarDateFormat(stringDate).split("T");
	const validDateStartOfDay = /* @__PURE__ */ new Date(`${datePart}T00:00:00`);
	let effectiveMinDate = null;
	if (minDate) {
		const minDateValue = new Date(minDate);
		effectiveMinDate = new Date(minDateValue.setHours(0, 0, 0, 0));
	}
	if (disablePastDates) {
		const today = /* @__PURE__ */ new Date();
		const todayStartOfDay = new Date(today.setHours(0, 0, 0, 0));
		if (!effectiveMinDate || todayStartOfDay > effectiveMinDate) effectiveMinDate = todayStartOfDay;
	}
	let effectiveMaxDate = null;
	if (maxDate) {
		const maxDateValue = new Date(maxDate);
		effectiveMaxDate = new Date(maxDateValue.setHours(0, 0, 0, 0));
	}
	if (disableFutureDates) {
		const today = /* @__PURE__ */ new Date();
		const todayStartOfDay = new Date(today.setHours(0, 0, 0, 0));
		if (!effectiveMaxDate || todayStartOfDay < effectiveMaxDate) effectiveMaxDate = todayStartOfDay;
	}
	if (effectiveMinDate && effectiveMaxDate) {
		if (effectiveMinDate > effectiveMaxDate) {
			const formattedMinDate = format(effectiveMinDate, internalFormat);
			const formattedMaxDate = format(effectiveMaxDate, internalFormat);
			return `Invalid date range: ${formattedMinDate.toUpperCase()} is after ${formattedMaxDate.toUpperCase()}`;
		}
		if (validDateStartOfDay < effectiveMinDate || validDateStartOfDay > effectiveMaxDate) {
			const formattedMinDate = format(effectiveMinDate, internalFormat);
			const formattedMaxDate = format(effectiveMaxDate, internalFormat);
			return `Date should be between ${formattedMinDate.toUpperCase()} - ${formattedMaxDate.toUpperCase()}`;
		}
	} else if (effectiveMinDate) {
		if (validDateStartOfDay < effectiveMinDate) return `Date must be after ${format(effectiveMinDate, internalFormat).toUpperCase()}`;
	} else if (effectiveMaxDate) {
		if (validDateStartOfDay > effectiveMaxDate) return `Date must be before ${format(effectiveMaxDate, internalFormat).toUpperCase()}`;
	}
	return true;
};
//#endregion
//#region node_modules/@powerhousedao/document-engineering/dist/src/scalars/components/date-picker-field/date-picker-field.js
const DatePickerField = withFieldValidation(DatePicker, { validations: { _datePickerType: validateDatePicker } });
DatePickerField.displayName = "DatePickerField";
//#endregion
export { DatePickerField as t };

//# sourceMappingURL=date-picker-field-DfPFIt41.js.map