import { GridExcelStyleEnums } from "../../enums/unitySystemEnums.mjs";
import { useAuthedUser } from "../../utilities/auth/useAuthedUser.mjs";
import { getDateFromString } from "../../UI/widgets/utils/dateUtils.mjs";
import { useGetLocalizedDateString, useGetLocalizedDateTimeString } from "./dateLocalizationHooks.mjs";
import { c } from "react-compiler-runtime";
import "react";
import { DateTime, IANAZone } from "luxon";
//#region src/udp/utilities/useDateStringColumnDef.js
const useDateStringColumnDef = (t0, t1, t2) => {
	const $ = c(9);
	const includeTime = t0 === void 0 ? false : t0;
	const timeZone = t1 === void 0 ? null : t1;
	const includeTimeZoneOffset = t2 === void 0 ? false : t2;
	const user = useAuthedUser();
	const tz = timeZone ?? user?.additionalProperties?.timeZone ?? "local";
	let t3;
	if ($[0] !== tz || $[1] !== user?.additionalProperties?.timeZone) {
		t3 = tz !== "local" && (tz === user?.additionalProperties?.timeZone || IANAZone.isValidZone(tz)) ? tz : "local";
		$[0] = tz;
		$[1] = user?.additionalProperties?.timeZone;
		$[2] = t3;
	} else t3 = $[2];
	const zone = t3;
	const getLocalizedDateTimeString = useGetLocalizedDateTimeString(zone, includeTimeZoneOffset);
	const getLocalizedDateString = useGetLocalizedDateString(zone);
	let t4;
	if ($[3] !== getLocalizedDateString || $[4] !== getLocalizedDateTimeString || $[5] !== includeTime || $[6] !== user || $[7] !== zone) {
		t4 = !user ? {} : {
			valueFormatter: (params) => {
				if (!params) return "";
				if (includeTime) return getLocalizedDateTimeString(params.value);
				else return getLocalizedDateString(params.value);
			},
			cellClass: includeTime ? GridExcelStyleEnums.DateTimeShortWithSeconds : GridExcelStyleEnums.DateShort,
			filter: "agDateColumnFilter",
			filterParams: {
				comparator: function(filterLocalDateAtMidnight, cellValue) {
					const cellDate = getDateFromString(cellValue);
					if (!cellDate) return null;
					const filterDateTimeMidnight = DateTime.fromJSDate(filterLocalDateAtMidnight).setZone(zone, { keepLocalTime: true });
					const cellDateTimeMidnight = DateTime.fromJSDate(cellDate, { zone }).set({
						hour: 0,
						minute: 0,
						second: 0,
						millisecond: 0
					});
					if (cellDateTimeMidnight < filterDateTimeMidnight) return -1;
					else if (cellDateTimeMidnight > filterDateTimeMidnight) return 1;
					else return 0;
				},
				buttons: ["apply", "reset"],
				closeOnApply: true,
				suppressAndOrCondition: true,
				filterOptions: [
					"equals",
					"lessThan",
					"greaterThan",
					"inRange"
				]
			}
		};
		$[3] = getLocalizedDateString;
		$[4] = getLocalizedDateTimeString;
		$[5] = includeTime;
		$[6] = user;
		$[7] = zone;
		$[8] = t4;
	} else t4 = $[8];
	return t4;
};
//#endregion
export { useDateStringColumnDef };

//# sourceMappingURL=useDateStringColumnDef.mjs.map