const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_MultiDayTimeSelect = require("../../../../pro/multiDayTimeSelect/MultiDayTimeSelect.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("./MultiDayTimeSelectModal.less");
//#region src/components/ticketBooking/components/addServiceVariant/MultiDayTimeSelectModal.tsx
const MultiDayTimeSelectModal = ({ open, productName, locale = "en", defaultStartDate, loading = false, maxDays = 30, separateStartEnd = false, onConfirm, onCancel }) => {
	const [value, setValue] = (0, react.useState)(null);
	const formRef = (0, react.useRef)(null);
	(0, react.useEffect)(() => {
		if (open) {
			const startDate = defaultStartDate || (0, dayjs.default)();
			setValue({
				startDate,
				endDate: startDate.add(1, "day"),
				duration: 1
			});
		}
	}, [open, defaultStartDate]);
	const handleChange = (newValue) => {
		setValue(newValue);
	};
	const handleConfirm = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				var _formRef$current;
				yield (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.validate();
				if (value) onConfirm(value.startDate, value.endDate, value.duration);
			} catch (error) {}
		});
		return function handleConfirm() {
			return _ref.apply(this, arguments);
		};
	}();
	const handleCancel = () => {
		if (loading) return;
		onCancel();
	};
	return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal, {
		open,
		title: productName || _pisell_utils.locales.getText("pisell2.text.product_name"),
		onCancel: handleCancel,
		onOk: handleConfirm,
		okText: _pisell_utils.locales.getText("pisell2.text.confirm"),
		cancelText: _pisell_utils.locales.getText("pisell2.text.cancel"),
		width: 600,
		destroyOnClose: true,
		confirmLoading: loading,
		closable: !loading,
		maskClosable: !loading,
		headerDivider: false,
		footerDivider: false,
		cancelButtonProps: { disabled: loading }
	}, /* @__PURE__ */ react.default.createElement(require_MultiDayTimeSelect.default, {
		ref: formRef,
		maxDays,
		defaultStartDate,
		separateStartEnd,
		value: value || void 0,
		onChange: handleChange,
		locale,
		disabled: loading
	}));
};
//#endregion
exports.default = MultiDayTimeSelectModal;
