const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_utils = require("../../utils.js");
const require_index = require("./components/ScheduleTimes/index.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_materials = require("@pisell/materials");
let antd_es_date_picker_locale_zh_CN = require("antd/es/date-picker/locale/zh_CN");
antd_es_date_picker_locale_zh_CN = require_runtime.__toESM(antd_es_date_picker_locale_zh_CN);
let antd_es_date_picker_locale_en_US = require("antd/es/date-picker/locale/en_US");
antd_es_date_picker_locale_en_US = require_runtime.__toESM(antd_es_date_picker_locale_en_US);
//#region src/components/eventBooking/components/scheduleCalendar/calendarItem.tsx
const CalendarItem = (props) => {
	var _utils$storage;
	const { month, schedulesData, selectDate, onSelect, isEdit, onChange, type } = props;
	const utils = require_useEngineContext.default().appHelper.utils || {};
	const locale = (utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 || (_utils$storage = _utils$storage.get("umi_locale")) === null || _utils$storage === void 0 ? void 0 : _utils$storage.includes("zh")) ? antd_es_date_picker_locale_zh_CN.default : antd_es_date_picker_locale_en_US.default;
	const scheduleMap = (0, react.useMemo)(() => new Map(schedulesData.map((schedule) => [schedule.date, schedule])), [schedulesData]);
	/**
	* @title: 月份切换
	* @description:
	* @param {string} type
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-12 11:48
	*/
	const handleMonth = (type) => {
		const date = /* @__PURE__ */ new Date(month + "-01");
		if (type === "prev") date.setMonth(date.getMonth() - 1);
		else date.setMonth(date.getMonth() + 1);
		onChange(date.toISOString().slice(0, 7), type);
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "month-item" }, /* @__PURE__ */ react.default.createElement("div", { className: "calendar-month" }, /* @__PURE__ */ react.default.createElement("div", {
		onClick: () => handleMonth("prev"),
		className: "calendar-month-icon"
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-chevron-left" })), /* @__PURE__ */ react.default.createElement("span", { className: "calendar-month-title" }, require_utils.formatMonthDisplay(month)), /* @__PURE__ */ react.default.createElement("div", {
		onClick: () => handleMonth("next"),
		className: "calendar-month-icon"
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-chevron-right" }))), type === "textList" ? /* @__PURE__ */ react.default.createElement(require_index.default, {
		month,
		schedulesData
	}) : /* @__PURE__ */ react.default.createElement(antd.Calendar, {
		locale,
		headerRender: () => null,
		fullscreen: false,
		value: (0, dayjs.default)(month),
		disabledDate: (currentDate) => {
			return !schedulesData.some((item) => currentDate.isSame(item.date)) || currentDate.format("YYYY-MM") !== month;
		},
		fullCellRender: (e) => {
			const isDisabled = !schedulesData.some((item) => e.isSame(item.date)) || e.format("YYYY-MM") !== month;
			const currentDayText = e.format("YYYY-MM-DD");
			const currentDayData = scheduleMap.get(currentDayText);
			const isCurrentMonth = e.format("YYYY-MM") === month;
			const isSelectDate = currentDayText === selectDate;
			const isExcluded = currentDayData === null || currentDayData === void 0 ? void 0 : currentDayData.isExcluded;
			let style = { color: isCurrentMonth ? "#101828" : "inherit" };
			const colors = !isEdit ? ["#7F56D9"] : (currentDayData === null || currentDayData === void 0 ? void 0 : currentDayData.color) || [];
			if (isDisabled) return /* @__PURE__ */ react.default.createElement("div", { style }, e.date());
			style = { background: require_utils.formatBackgroundColors(colors) };
			return /* @__PURE__ */ react.default.createElement("div", {
				className: `caleddar-date-cell ${isSelectDate ? "select" : ""} ${isExcluded ? "excluded" : ""}`,
				onClick: () => onSelect(currentDayText, scheduleMap.get(currentDayText)),
				style: {
					position: "absolute",
					left: "50%",
					top: "50%",
					transform: "translate(-50%, -50%)",
					display: "flex",
					alignItems: "center",
					justifyContent: "center"
				}
			}, /* @__PURE__ */ react.default.createElement("div", {
				className: `caleddar-date ${colors.filter(Boolean).length ? "has-status" : ""} ${isCurrentMonth ? "" : "disabled-date"}`,
				style
			}, e.date()));
		}
	}));
};
//#endregion
exports.default = CalendarItem;
