import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import MultiDayTimeSelect from "../../../../pro/multiDayTimeSelect/MultiDayTimeSelect.js";
import dayjs from "dayjs";
import React, { useEffect, useRef, useState } from "react";
import { locales } from "@pisell/utils";
import { PisellModal } from "@pisell/materials";
import "./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] = useState(null);
	const formRef = useRef(null);
	useEffect(() => {
		if (open) {
			const startDate = defaultStartDate || dayjs();
			setValue({
				startDate,
				endDate: startDate.add(1, "day"),
				duration: 1
			});
		}
	}, [open, defaultStartDate]);
	const handleChange = (newValue) => {
		setValue(newValue);
	};
	const handleConfirm = function() {
		var _ref = _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.createElement(PisellModal, {
		open,
		title: productName || locales.getText("pisell2.text.product_name"),
		onCancel: handleCancel,
		onOk: handleConfirm,
		okText: locales.getText("pisell2.text.confirm"),
		cancelText: locales.getText("pisell2.text.cancel"),
		width: 600,
		destroyOnClose: true,
		confirmLoading: loading,
		closable: !loading,
		maskClosable: !loading,
		headerDivider: false,
		footerDivider: false,
		cancelButtonProps: { disabled: loading }
	}, /* @__PURE__ */ React.createElement(MultiDayTimeSelect, {
		ref: formRef,
		maxDays,
		defaultStartDate,
		separateStartEnd,
		value: value || void 0,
		onChange: handleChange,
		locale,
		disabled: loading
	}));
};
//#endregion
export { MultiDayTimeSelectModal as default };
