const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_utils = require("../../utils.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
//#region src/components/booking/materiels/duration/index.tsx
const _excluded = [
	"locale",
	"slice",
	"timeObjChange",
	"selectProps",
	"duration",
	"usableTime",
	"startDate",
	"timeObj"
];
const Duration = (props) => {
	const { locale = "en", slice = 5, timeObjChange, selectProps, duration, usableTime, startDate, timeObj } = props, resetProps = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const startDateStr = (0, react.useMemo)(() => (0, dayjs.default)(startDate).format("YYYY-MM-DD HH:mm:ss"), [startDate]);
	/**
	* @title: 时间切片
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-09 13:37
	*/
	const times = (0, react.useMemo)(() => {
		if (timeObj) return timeObj.durationSlicesBasedOnTime;
		let { durationSlicesBasedOnTime } = require_utils.sliceDayIntoFiveMinutes(slice, locale);
		let _duration = typeof duration === "object" ? duration.type : duration;
		if (_duration === "flexible") {
			let timeValue = require_utils.getEndDate(startDate, _duration, (usableTime === null || usableTime === void 0 ? void 0 : usableTime.end_at) ? (0, dayjs.default)(usableTime === null || usableTime === void 0 ? void 0 : usableTime.end_at) : null).diff(startDate, "minute");
			durationSlicesBasedOnTime.unshift({
				label: _pisell_utils.locales.getText("pisell2.text.flexible"),
				value: require_utils.flexibleObj.create(timeValue)
			});
		}
		if (resetProps.value && !durationSlicesBasedOnTime.some((d) => d.value === resetProps.value)) durationSlicesBasedOnTime.unshift({
			label: require_utils.getDiscountTime(resetProps.value),
			value: resetProps.value,
			disabled: true
		});
		return durationSlicesBasedOnTime;
	}, [
		timeObj === null || timeObj === void 0 ? void 0 : timeObj.durationSlicesBasedOnTime,
		slice,
		locale,
		duration,
		startDateStr,
		usableTime === null || usableTime === void 0 ? void 0 : usableTime.end_at
	]);
	(0, react.useEffect)(() => {
		timeObjChange === null || timeObjChange === void 0 || timeObjChange(times);
	}, [times]);
	const renderOptions = (0, react.useCallback)((array, value = "value", label = "label") => {
		return array.map((d) => {
			return /* @__PURE__ */ react.default.createElement(antd.Select.Option, {
				value: d[value],
				key: d[value],
				disabled: d.disabled
			}, d[label]);
		});
	}, []);
	const options = (0, react.useMemo)(() => {
		console.log("render form options");
		return renderOptions(times);
	}, [times]);
	return /* @__PURE__ */ react.default.createElement(antd.Select, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, selectProps), resetProps), options);
};
//#endregion
exports.default = Duration;
