import { Field } from "../../../utilities/form/Field.mjs";
import { FluentDatePicker } from "../pickers/FluentDatePicker.mjs";
import { Grid } from "../../Grid.mjs";
import { c } from "react-compiler-runtime";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
//#region src/UI/inputs/fieldArrayCard/DateRangeField.jsx
const DateRangeField = (props) => {
	const $ = c(40);
	const { fieldName, startDateProps: t0, endDateProps: t1, sameRow: t2, initialValues } = props;
	let t3;
	if ($[0] !== t0) {
		t3 = t0 === void 0 ? {} : t0;
		$[0] = t0;
		$[1] = t3;
	} else t3 = $[1];
	const startDateProps = t3;
	let t4;
	if ($[2] !== t1) {
		t4 = t1 === void 0 ? {} : t1;
		$[2] = t1;
		$[3] = t4;
	} else t4 = $[3];
	const endDateProps = t4;
	const sameRow = t2 === void 0 ? false : t2;
	const [maxStartDate, setMaxStartDate] = useState();
	const [minEndDate, setMinEndDate] = useState();
	const { t } = useTranslation();
	let t5;
	let t6;
	if ($[4] !== initialValues || $[5] !== startDateProps.name) {
		t5 = () => {
			const currentStartDate = initialValues[startDateProps?.name ?? "startDate"];
			if (currentStartDate) {
				const minDate = new Date(currentStartDate);
				minDate.setDate(minDate?.getDate() + 1);
				setMinEndDate(minDate);
			} else setMinEndDate(void 0);
		};
		t6 = [initialValues, startDateProps.name];
		$[4] = initialValues;
		$[5] = startDateProps.name;
		$[6] = t5;
		$[7] = t6;
	} else {
		t5 = $[6];
		t6 = $[7];
	}
	useEffect(t5, t6);
	let t7;
	let t8;
	if ($[8] !== endDateProps.name || $[9] !== initialValues) {
		t7 = () => {
			const currentEndDate = initialValues[endDateProps?.name ?? "endDate"];
			if (currentEndDate) {
				const maxDate = new Date(currentEndDate);
				maxDate.setDate(maxDate?.getDate() - 1);
				maxDate.setHours(0, 0, 0, 0);
				setMaxStartDate(maxDate);
			} else setMaxStartDate(void 0);
		};
		t8 = [endDateProps.name, initialValues];
		$[8] = endDateProps.name;
		$[9] = initialValues;
		$[10] = t7;
		$[11] = t8;
	} else {
		t7 = $[10];
		t8 = $[11];
	}
	useEffect(t7, t8);
	const t9 = sameRow ? 2 : 0;
	const t10 = sameRow ? 6 : 12;
	let t11;
	if ($[12] !== startDateProps.label || $[13] !== t) {
		t11 = startDateProps?.label ?? t("Start Date");
		$[12] = startDateProps.label;
		$[13] = t;
		$[14] = t11;
	} else t11 = $[14];
	const t12 = `${fieldName}.${startDateProps?.name ?? "startDate"}`;
	const t13 = `${fieldName}.${startDateProps?.name ?? "startDate"}`;
	let t14;
	if ($[15] !== maxStartDate || $[16] !== startDateProps || $[17] !== t11 || $[18] !== t12 || $[19] !== t13) {
		t14 = /* @__PURE__ */ React.createElement(Field, {
			...startDateProps,
			parse: _temp,
			format: _temp2,
			label: t11,
			name: t12,
			key: t13,
			component: FluentDatePicker,
			size: "small",
			maxDate: maxStartDate,
			allowNull: true
		});
		$[15] = maxStartDate;
		$[16] = startDateProps;
		$[17] = t11;
		$[18] = t12;
		$[19] = t13;
		$[20] = t14;
	} else t14 = $[20];
	let t15;
	if ($[21] !== t10 || $[22] !== t14) {
		t15 = /* @__PURE__ */ React.createElement(Grid, {
			item: true,
			xs: 12,
			sm: t10
		}, t14);
		$[21] = t10;
		$[22] = t14;
		$[23] = t15;
	} else t15 = $[23];
	const t16 = sameRow ? 6 : 12;
	let t17;
	if ($[24] !== endDateProps.label || $[25] !== t) {
		t17 = endDateProps?.label ?? t("End Date");
		$[24] = endDateProps.label;
		$[25] = t;
		$[26] = t17;
	} else t17 = $[26];
	const t18 = `${fieldName}.${endDateProps?.name ?? "endDate"}`;
	const t19 = `${fieldName}.${endDateProps?.name ?? "endDate"}`;
	let t20;
	if ($[27] !== endDateProps || $[28] !== minEndDate || $[29] !== t17 || $[30] !== t18 || $[31] !== t19) {
		t20 = /* @__PURE__ */ React.createElement(Field, {
			...endDateProps,
			parse: _temp3,
			format: _temp4,
			label: t17,
			name: t18,
			key: t19,
			component: FluentDatePicker,
			size: "small",
			minDate: minEndDate,
			allowNull: true
		});
		$[27] = endDateProps;
		$[28] = minEndDate;
		$[29] = t17;
		$[30] = t18;
		$[31] = t19;
		$[32] = t20;
	} else t20 = $[32];
	let t21;
	if ($[33] !== t16 || $[34] !== t20) {
		t21 = /* @__PURE__ */ React.createElement(Grid, {
			item: true,
			xs: 12,
			sm: t16
		}, t20);
		$[33] = t16;
		$[34] = t20;
		$[35] = t21;
	} else t21 = $[35];
	let t22;
	if ($[36] !== t15 || $[37] !== t21 || $[38] !== t9) {
		t22 = /* @__PURE__ */ React.createElement(Grid, {
			container: true,
			spacing: t9
		}, t15, t21);
		$[36] = t15;
		$[37] = t21;
		$[38] = t9;
		$[39] = t22;
	} else t22 = $[39];
	return t22;
};
function _temp(value) {
	return value ? value : null;
}
function _temp2(value_0) {
	return value_0 ? value_0 : null;
}
function _temp3(value_1) {
	return value_1 ?? null;
}
function _temp4(value_2) {
	return value_2 ?? null;
}
//#endregion
export { DateRangeField as default };

//# sourceMappingURL=DateRangeField.mjs.map