import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { formatDateKey, getWeekDays } from "../../utils.js";
import { useVenueBookingContext } from "../../context.js";
import DateNavigator from "./components/DateNavigator.js";
import DayTabs from "./components/DayTabs.js";
import CourtFilter from "./components/CourtFilter.js";
import TimeGrid from "./components/TimeGrid.js";
import React, { useCallback, useRef } from "react";
import { locales } from "@pisell/utils";
//#region src/components/venueBooking/components/VenueSelection/index.tsx
/**
* venueBooking 场地选择步骤（Step 1）
* 包含日期导航、周视图、场地筛选、价格图例、时段网格等子组件
*/
function VenueSelection() {
	const { setAnchorDate, anchorDate, fetchWeekData } = useVenueBookingContext();
	const tableSectionRef = useRef(null);
	/** 翻周时：更新 anchorDate + 拉取新一周的资源可用性数据 */
	const navigateWeek = useCallback(function() {
		var _ref = _asyncToGenerator(function* (offset) {
			const newAnchor = anchorDate.add(offset, "day");
			setAnchorDate(newAnchor);
			const days = getWeekDays(newAnchor);
			yield fetchWeekData(formatDateKey(days[0]), formatDateKey(days[days.length - 1]));
		});
		return function(_x) {
			return _ref.apply(this, arguments);
		};
	}(), [
		anchorDate,
		setAnchorDate,
		fetchWeekData
	]);
	function goPrevWeek() {
		navigateWeek(-7);
	}
	function goNextWeek() {
		navigateWeek(7);
	}
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "rounded-b-[24px] bg-white p-3 shadow-[0_10px_40px_rgba(20,20,20,0.06)] ring-1 ring-black/6 md:rounded-[28px] md:p-6" }, /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-2 xl:flex-row xl:items-center xl:justify-between" }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h2", { className: "text-2xl font-extrabold leading-tight text-zinc-900 md:text-[30px]" }, locales.getText("pisell2.venue.step1.title") || "选择场地"), /* @__PURE__ */ React.createElement("p", { className: "mt-1 text-xs leading-5 text-zinc-500 md:mt-2 md:text-sm md:leading-6" }, locales.getText("pisell2.venue.step1.subtitle") || "仅显示可用时段和价格。")), /* @__PURE__ */ React.createElement(DateNavigator, {
		onPrevWeek: goPrevWeek,
		onNextWeek: goNextWeek
	})), /* @__PURE__ */ React.createElement("div", { className: "mt-3 md:mt-5" }, /* @__PURE__ */ React.createElement(DayTabs, {
		onPrevWeek: goPrevWeek,
		onNextWeek: goNextWeek
	})), /* @__PURE__ */ React.createElement(CourtFilter, null)), /* @__PURE__ */ React.createElement("div", {
		ref: tableSectionRef,
		className: "w-full max-w-full isolate rounded-[28px] bg-white shadow-[0_10px_40px_rgba(20,20,20,0.06)] ring-1 ring-black/6"
	}, /* @__PURE__ */ React.createElement(TimeGrid, null)));
}
//#endregion
export { VenueSelection as default };
