const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let _ant_design_icons = require("@ant-design/icons");
require("./index.less");
//#region src/components/booking/info/dateRange/index.tsx
const disabledDate = (current, position, currentDate) => {
	if (position === "start") return false;
	if (position === "end" && current.endOf("day") && (currentDate === null || currentDate === void 0 ? void 0 : currentDate[0])) return (0, dayjs.default)(currentDate === null || currentDate === void 0 ? void 0 : currentDate[0].add(8, "months").format("YYYY-MM-DD")) < current.startOf("day") || current.startOf("day") <= (currentDate === null || currentDate === void 0 ? void 0 : currentDate[0]);
	return current && current <= (currentDate === null || currentDate === void 0 ? void 0 : currentDate[0]);
};
const DateRange = ({ state, dispatch, key }) => {
	const [value, setValue] = (0, react.useState)([]);
	(0, react.useEffect)(() => {
		var _state$date, _state$date2;
		const lists = [(_state$date = state.date) === null || _state$date === void 0 ? void 0 : _state$date.value, (_state$date2 = state.date) === null || _state$date2 === void 0 ? void 0 : _state$date2.end_date];
		setValue(lists);
		console.log("lists", lists);
	}, [state.date]);
	/**
	* @title: 点击确定
	* @description:
	* @param {any} e
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-12 15:39
	*/
	const dateChange = (e) => {
		dispatch({
			type: "setDate",
			payload: {
				value: e[0],
				end_date: e[1],
				edit: true
			}
		});
	};
	/**
	* @title: 格式化语言
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-12-09 17:47
	*/
	const formatLocale = (0, react.useMemo)(() => {
		const locale = state === null || state === void 0 ? void 0 : state.locale;
		return locale === "en" || locale === "en-US" ? "DD/MM/YYYY" : "YYYY-MM-DD";
	}, [state === null || state === void 0 ? void 0 : state.locale, state.date]);
	return (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("pisell-lowcode__booking-service-header-date-range", { "pisell-lowcode__booking-service-header-date-range-terminal": state.isTerminalDayBookingPage }) }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Page, null, /* @__PURE__ */ react.default.createElement(_pisell_materials.DatePicker.RangePicker, {
			key,
			inputReadOnly: true,
			allowClear: false,
			size: "large",
			style: {
				width: "100%",
				padding: 0
			},
			suffixIcon: !state.disabledEdit ? /* @__PURE__ */ react.default.createElement(_ant_design_icons.CalendarOutlined, null) : null,
			disabledDate,
			value: [value[0], value[1]],
			onChange: dateChange,
			format: formatLocale,
			isHideCustomSelect: true,
			endDateDays: 1
		}))));
	}, [
		value,
		state.disabledEdit,
		state === null || state === void 0 ? void 0 : state.locale
	]);
};
//#endregion
exports.default = DateRange;
exports.disabledDate = disabledDate;
