import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { Context } from "../../model.js";
import { getOpenHoursByDate } from "./serve.js";
import { getTimeRange } from "./utils.js";
import dayjs from "dayjs";
import React, { useContext, useEffect } from "react";
import { Alert } from "antd";
import { useRequest } from "ahooks";
import "./index.less";
//#region src/components/schedules/components/CurrentDay/index.tsx
const CurrentDay = (props) => {
	var _state$currentSelectD;
	const { onClose, currentDay } = props;
	const { state, dispatch } = useContext(Context);
	const _getOpenHoursByDate = useRequest(getOpenHoursByDate, {
		manual: true,
		onSuccess: ({ data }) => {
			dispatch({
				type: "setState",
				payload: { currentSelectDayDetail: _objectSpread2(_objectSpread2({}, state.currentSelectDayDetail), {}, {
					times: data,
					timeStr: getTimeRange(data)
				}) }
			});
		}
	});
	useEffect(() => {
		if (currentDay) _getOpenHoursByDate.run({ date: dayjs(currentDay).format("YYYY-MM-DD") });
	}, [currentDay]);
	return currentDay ? /* @__PURE__ */ React.createElement(Alert, {
		onClose,
		closable: true,
		className: "current-day-alert",
		message: dayjs(currentDay).format("ddd MMMM YYYY"),
		description: ((_state$currentSelectD = state.currentSelectDayDetail) === null || _state$currentSelectD === void 0 ? void 0 : _state$currentSelectD.timeStr) || " "
	}) : null;
};
//#endregion
export { CurrentDay as default };
