import { formatBackgroundColors } from "../products/utils.js";
import dayjs from "dayjs";
import React, { useMemo } from "react";
import { Calendar } from "antd";
//#region src/components/schedules/calendar/calendarItem.tsx
const CalendarItem = (props) => {
	const { month, schedulesData, selectDate, onSelect, isEdit } = props;
	const scheduleMap = useMemo(() => new Map(schedulesData.map((schedule) => [schedule.date, schedule])), [schedulesData]);
	let startDate = dayjs(month).startOf("month").format("YYYY-MM-DD");
	let endDate = dayjs(month).endOf("month").format("YYYY-MM-DD");
	return /* @__PURE__ */ React.createElement("div", { className: "month-item" }, /* @__PURE__ */ React.createElement("div", { className: "caleddar-month" }, dayjs(month).format("MMMM")), /* @__PURE__ */ React.createElement(Calendar, {
		headerRender: () => null,
		fullscreen: false,
		value: dayjs(month),
		disabledDate: (currentDate) => {
			return currentDate.isAfter(endDate) || currentDate.isBefore(startDate);
		},
		fullCellRender: (e) => {
			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 = {};
			const colors = !isEdit ? ["#7D89B0"] : (currentDayData === null || currentDayData === void 0 ? void 0 : currentDayData.color) || [];
			style = { background: formatBackgroundColors(colors) };
			if (e.isAfter(endDate) || e.isBefore(startDate)) return e.date();
			return /* @__PURE__ */ React.createElement("div", {
				className: `caleddar-date-cell ${isSelectDate ? "select" : ""} ${isExcluded ? "excluded" : ""}`,
				onClick: () => onSelect(currentDayText, scheduleMap.get(currentDayText))
			}, /* @__PURE__ */ React.createElement("div", {
				className: `caleddar-date ${colors.filter(Boolean).length ? "has-status" : ""} ${isCurrentMonth ? "" : "disabled-date"}`,
				style
			}, e.date()));
		}
	}));
};
//#endregion
export { CalendarItem as default };
