const require_runtime = require("../../../../../../../_virtual/_rolldown/runtime.js");
const require_state = require("../state.js");
const require_index = require("./WeekItem/index.js");
const require_index$1 = require("./CallToBook/index.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./index.less");
//#region src/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateWeek/index.tsx
const CalenDateWeek = (props) => {
	const { currentDate, dateChange, productId, timeList, dateLimitData, getLimitData, cutTime } = props;
	const [weekList, setWeekList] = (0, react.useState)([]);
	const [showCallToBook, setShowCallToBook] = (0, react.useState)(false);
	const weekListRef = (0, react.useRef)(null);
	const [selectStatus, setSelectStatus] = (0, react.useState)("");
	const [selectDisabled, setSelectDisabled] = (0, react.useState)(false);
	/**
	* @title: 根据时间生成本周数据
	* @description:
	* @return {*}
	* @Author: xiangxiang.shao
	* @Date: 2024-02-07 15:13
	*/
	const initCurrentWeekData = (dateText) => {
		let startOfWeek = (0, dayjs.default)(dateText).startOf("week");
		if (startOfWeek.day() !== 0) startOfWeek.subtract(startOfWeek.day(), "days");
		let weekDates = [];
		for (let i = 0; i < 7; i++) {
			let date = startOfWeek.clone().add(i, "days");
			weekDates.push(date.format("YYYY-MM-DD"));
		}
		return weekDates;
	};
	/**
	* @title: 构造初始化周数据
	* @description:
	* @return {*}
	* @Author: xiangxiang.shao
	* @Date: 2024-02-07 15:13
	*/
	const initWeekData = () => {
		setWeekList(initCurrentWeekData(currentDate));
	};
	/**
	* @title: 判断是否重新生成还是滚动到指定位置
	* @description:
	* @return {*}
	* @Author: xiangxiang.shao
	* @Date: 2024-02-07 15:13
	*/
	const init = () => {
		initWeekData();
	};
	(0, react.useEffect)(() => {
		init();
	}, [currentDate]);
	(0, react.useEffect)(() => {
		const { status, disabled } = require_state.getStatus(dateLimitData, currentDate, cutTime);
		if (require_state.getCallToBookStatus(currentDate, dateLimitData, cutTime) && (status === "lots_of_space" || status === "filling_up_fast")) setShowCallToBook(true);
		else setShowCallToBook(false);
		setSelectStatus(status);
		setSelectDisabled(disabled);
	}, [
		currentDate,
		timeList,
		cutTime
	]);
	(0, react.useEffect)(() => {
		const index = weekList.findIndex((date) => date === currentDate);
		if ((weekListRef === null || weekListRef === void 0 ? void 0 : weekListRef.current) && index !== -1) weekListRef.current.scrollLeft = (index - 1) * 50;
	}, [currentDate, weekList]);
	return /* @__PURE__ */ React.createElement("div", { className: "calendar-week-wrap" }, /* @__PURE__ */ React.createElement("div", {
		ref: weekListRef,
		className: "calendar-week-list"
	}, /* @__PURE__ */ React.createElement(require_index.default, {
		weekList,
		currentDate,
		dateChange,
		isActive: true,
		productId,
		setCurrentDate: dateChange,
		timeList,
		dateLimitData,
		cutTime
	})), selectStatus === "sold_out" || selectDisabled ? /* @__PURE__ */ React.createElement("div", { className: "disabled-status" }, /* @__PURE__ */ React.createElement(_pisell_materials.Iconfont, { className: (0, classnames.default)("disabled-icon", "iconhourglass_disabled_wght300_24px") }), /* @__PURE__ */ React.createElement("div", { className: "disabled-status-text" }, selectDisabled ? 2 : 5)) : null, /* @__PURE__ */ React.createElement(require_index$1.default, { show: showCallToBook }));
};
//#endregion
exports.default = CalenDateWeek;
