const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_PisellTimeNavigator = require("../pisellTimeNavigator/PisellTimeNavigator.js");
const require_PisellReservationSchedule = require("../pisellReservationSchedule/PisellReservationSchedule.js");
const require_formatScheduleAtLabel = require("./utils/formatScheduleAtLabel.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
require("./PisellReservationScheduleBand.less");
//#region src/components/pisellReservationScheduleBand/PisellReservationScheduleBand.tsx
function startOfDay(d) {
	return d.startOf("day");
}
function withTimeOnDate(dateDay, timeSource) {
	return startOfDay(dateDay).hour(timeSource.hour()).minute(timeSource.minute()).second(0).millisecond(0);
}
/**
* 预约顶栏组合：营业日切换 + 锚定到选中日的时间导航轴
*/
function PisellReservationScheduleBand(props) {
	const { value: valueProp, onChange, defaultValue, scheduleProps, timeNavigatorProps, scheduleStartSlot, scheduleEndSlot, scheduleAfterDateSlot, dataLoading = false, dataLoadingTip, hideTimeNavigator = false, className, style, scheduleRowClassName } = props;
	const isControlled = valueProp !== void 0;
	const [internal, setInternal] = (0, react.useState)(() => {
		var _defaultValue$date, _defaultValue$at;
		const d = (_defaultValue$date = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.date) !== null && _defaultValue$date !== void 0 ? _defaultValue$date : (0, dayjs.default)().startOf("day");
		const atSrc = (_defaultValue$at = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.at) !== null && _defaultValue$at !== void 0 ? _defaultValue$at : (0, dayjs.default)();
		return {
			date: startOfDay((0, dayjs.default)(d)),
			at: withTimeOnDate((0, dayjs.default)(d), (0, dayjs.default)(atSrc))
		};
	});
	const effective = isControlled ? valueProp : internal;
	const emit = (0, react.useCallback)((next) => {
		/** at 保留时间轴返回的绝对时刻（跨日营业时可能为锚定日的次日） */
		const normalized = {
			date: startOfDay(next.date),
			at: next.at
		};
		if (!isControlled) setInternal(normalized);
		onChange === null || onChange === void 0 || onChange(normalized);
	}, [isControlled, onChange]);
	const handleDateChange = (0, react.useCallback)((d) => {
		emit({
			date: startOfDay(d),
			at: withTimeOnDate(d, effective.at)
		});
	}, [emit, effective.at]);
	const handleTimeChange = (0, react.useCallback)((t) => {
		/** 顶栏 date 保持营业日锚定日；跨自然日时刻由 formatScheduleAtLabel 展示为「MM-DD HH:mm」 */
		emit({
			date: startOfDay(effective.date),
			at: t
		});
	}, [emit, effective.date]);
	const formatTimeLabel = (0, react.useCallback)((t) => require_formatScheduleAtLabel.formatScheduleAtLabel(t, effective.date), [effective.date]);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("pisell-reservation-schedule-band", dataLoading && "pisell-reservation-schedule-band--data-loading", className),
		style
	}, dataLoading ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-reservation-schedule-band-data-loading-overlay",
		"aria-busy": "true",
		"aria-live": "polite"
	}, /* @__PURE__ */ react.default.createElement(antd.Spin, {
		size: "small",
		tip: dataLoadingTip != null ? dataLoadingTip : void 0
	})) : null, /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("pisell-reservation-schedule-band-schedule-row", scheduleRowClassName) }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-schedule-band-slot-start" }, scheduleStartSlot), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-schedule-band-schedule" }, /* @__PURE__ */ react.default.createElement(require_PisellReservationSchedule.PisellReservationSchedule, require_objectSpread2._objectSpread2({
		value: effective.date,
		onChange: handleDateChange
	}, scheduleProps)), scheduleAfterDateSlot ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-schedule-band-after-date" }, scheduleAfterDateSlot) : null), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-schedule-band-slot-end" }, scheduleEndSlot)), hideTimeNavigator ? null : /* @__PURE__ */ react.default.createElement("div", { className: "pisell-reservation-schedule-band-navigator" }, /* @__PURE__ */ react.default.createElement(require_PisellTimeNavigator.PisellTimeNavigator, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({
		referenceDate: effective.date,
		value: effective.at
	}, timeNavigatorProps), {}, {
		onChange: handleTimeChange,
		formatTimeLabel
	}))));
}
PisellReservationScheduleBand.displayName = "PisellReservationScheduleBand";
//#endregion
exports.PisellReservationScheduleBand = PisellReservationScheduleBand;
