import useComponents from "../../../../../hooks/useComponents.js";
import { clearDataByStepKey, getResourceTitle, processResourceList } from "../../../utils.js";
import { useAppointmentBookingContext } from "../../../context.js";
import { contextUtils, useAppointmentBooking } from "../../../hooks.js";
import React, { useMemo } from "react";
//#region src/components/appointmentBooking/components/TimeSlicing/components/SelectDateOS.tsx
const SelectDate = (props) => {
	const { onDateChange, times, currentDate } = props;
	const appointmentBooking = useAppointmentBooking();
	const { currentSelectedResources, setTimes } = useAppointmentBookingContext();
	const utils = contextUtils();
	const [SelectDateOS] = useComponents({ components: ["SelectDateOS"] });
	/**
	* @description: 获取资源代码
	* @param {*}
	* @return {*}
	*/
	const resourceCode = useMemo(() => {
		const { resourceSort } = (appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams) || {};
		const { resourceCodes } = processResourceList(appointmentBooking.getResourcesList(), resourceSort);
		return (resourceCodes === null || resourceCodes === void 0 ? void 0 : resourceCodes[0]) || "";
	}, []);
	/**
	* @description: 获取资源名称
	* @param {*} useMemo
	* @return {*}
	*/
	const currentResourceName = useMemo(() => {
		var _currentSelectedResou;
		const currentResource = currentSelectedResources === null || currentSelectedResources === void 0 || (_currentSelectedResou = currentSelectedResources[0]) === null || _currentSelectedResou === void 0 ? void 0 : _currentSelectedResou.currentSelectedResource;
		const resourceItem = (currentResource === null || currentResource === void 0 ? void 0 : currentResource.resourceItem) || {};
		return getResourceTitle(appointmentBooking, resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.code, utils, resourceItem);
	}, [currentSelectedResources]);
	/**
	* @description: 跳转到服务步骤
	* @param {any} step
	* @return {*}
	*/
	const onStepChange = () => {
		clearDataByStepKey("select-service", appointmentBooking, setTimes);
		const serviceIndex = appointmentBooking.getStepList().findIndex((item) => (item === null || item === void 0 ? void 0 : item.key) === "select-service");
		appointmentBooking.gotoStep(serviceIndex);
	};
	return SelectDateOS ? /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(SelectDateOS, {
		isTimeSlicing: true,
		currentDate,
		resourceCode,
		resourceName: currentResourceName,
		onDateChange,
		onStepChange,
		times
	})) : null;
};
//#endregion
export { SelectDate as default };
