import { PisellReservationCore } from "../PisellReservation.js";
import dayjs from "dayjs";
import React, { useCallback, useMemo } from "react";
import { locales } from "@pisell/utils";
import { PisellModal } from "@pisell/materials";
import "./SelectFloorMapResourceDialog.less";
//#region src/plus/pisellReservation/components/SelectFloorMapResourceDialog.tsx
const I18N_TITLE = "pisell-reservation.select-resource.title";
const DIALOG_WIDTH = "99%";
const DIALOG_BODY_STYLE = {
	padding: 0,
	height: "100%"
};
function normalizeScheduleValue(value) {
	if (value == null) return void 0;
	const at = dayjs(typeof value === "string" ? value : value.at);
	if (!at.isValid()) return void 0;
	const rawDate = typeof value === "string" ? void 0 : value.date;
	const parsedDate = dayjs(rawDate);
	return {
		date: rawDate != null && parsedDate.isValid() ? parsedDate.startOf("day") : at.startOf("day"),
		at
	};
}
function SelectFloorMapResourceDialog({ open, onClose, onClick, reservationBiz, businessCode, associatedMenuListIds, scheduleValue, floorPlanId, floorPlanCode, floorPlanCanvasWidth, floorPlanCanvasHeight, dataSources, floorMap, title }) {
	const handleSelectResource = useCallback((payload) => {
		onClick === null || onClick === void 0 || onClick(payload);
	}, [onClick]);
	const resourceSelectMode = useMemo(() => ({
		enabled: true,
		onSelectResource: handleSelectResource
	}), [handleSelectResource]);
	const normalizedScheduleValue = useMemo(() => normalizeScheduleValue(scheduleValue), [scheduleValue]);
	return /* @__PURE__ */ React.createElement(PisellModal, {
		platform: "pc",
		open,
		onCancel: onClose,
		title: title !== null && title !== void 0 ? title : locales.getText(I18N_TITLE),
		footer: null,
		destroyOnClose: true,
		width: DIALOG_WIDTH,
		className: "pisell-select-floor-map-resource-dialog-modal",
		bodyStyle: DIALOG_BODY_STYLE,
		wrapClassName: "pisell-select-floor-map-resource-dialog"
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell-select-floor-map-resource-dialog-content" }, /* @__PURE__ */ React.createElement(PisellReservationCore, {
		reservationBiz: reservationBiz !== null && reservationBiz !== void 0 ? reservationBiz : businessCode,
		associatedMenuListIds,
		scheduleValue: normalizedScheduleValue,
		floorPlanId,
		floorPlanCode,
		floorPlanCanvasWidth,
		floorPlanCanvasHeight,
		dataSources,
		floorMap,
		bodyViewSwitchable: false,
		lockedBodyView: "floorMap",
		resourceSelectMode
	})));
}
//#endregion
export { SelectFloorMapResourceDialog as default };
