import dayjs from "dayjs";
import React, { useEffect, useMemo, useState } from "react";
import { DatePicker, Page } from "@pisell/materials";
import classNames from "classnames";
import { CalendarOutlined } from "@ant-design/icons";
import "./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 dayjs(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] = useState([]);
	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 = 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 useMemo(() => {
		return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: classNames("pisell-lowcode__booking-service-header-date-range", { "pisell-lowcode__booking-service-header-date-range-terminal": state.isTerminalDayBookingPage }) }, /* @__PURE__ */ React.createElement(Page, null, /* @__PURE__ */ React.createElement(DatePicker.RangePicker, {
			key,
			inputReadOnly: true,
			allowClear: false,
			size: "large",
			style: {
				width: "100%",
				padding: 0
			},
			suffixIcon: !state.disabledEdit ? /* @__PURE__ */ React.createElement(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
export { DateRange as default, disabledDate };
