const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_resolveIsMultiDayProduct = require("./resolveIsMultiDayProduct.js");
const require_patchCacheItemDateRange = require("./patchCacheItemDateRange.js");
//#region src/plus/salesSdk/utils/ensureMultiDayRangeSelected.ts
function ensureMultiDayRangeSelected(_x) {
	return _ensureMultiDayRangeSelected.apply(this, arguments);
}
function _ensureMultiDayRangeSelected() {
	_ensureMultiDayRangeSelected = require_asyncToGenerator._asyncToGenerator(function* (input) {
		var _input$hosts, _input$detail, _input$catalogItem, _input$product, _input$cacheItem, _input$defaultStartDa;
		if (!require_resolveIsMultiDayProduct.resolveIsMultiDayProduct(input.detail, input.cacheItem, input.catalogItem, input.product)) return { status: "skip" };
		if (input.existingRange) {
			const cacheItem = input.cacheItem ? require_patchCacheItemDateRange.patchCacheItemDateRange(input.cacheItem, input.existingRange) : void 0;
			return {
				status: "ok",
				range: input.existingRange,
				cacheItem
			};
		}
		const openMultiDay = (_input$hosts = input.hosts) === null || _input$hosts === void 0 ? void 0 : _input$hosts.openMultiDaySelect;
		if (!openMultiDay) return { status: "missing_host" };
		const range = yield openMultiDay({
			productName: ((_input$detail = input.detail) === null || _input$detail === void 0 ? void 0 : _input$detail.title) || ((_input$catalogItem = input.catalogItem) === null || _input$catalogItem === void 0 ? void 0 : _input$catalogItem.title) || ((_input$product = input.product) === null || _input$product === void 0 ? void 0 : _input$product.title) || ((_input$cacheItem = input.cacheItem) === null || _input$cacheItem === void 0 || (_input$cacheItem = _input$cacheItem._extend) === null || _input$cacheItem === void 0 ? void 0 : _input$cacheItem.product_name),
			defaultStartDate: (_input$defaultStartDa = input.defaultStartDate) !== null && _input$defaultStartDa !== void 0 ? _input$defaultStartDa : null
		});
		if (!range) return { status: "cancelled" };
		return {
			status: "ok",
			range,
			cacheItem: input.cacheItem ? require_patchCacheItemDateRange.patchCacheItemDateRange(input.cacheItem, range) : void 0
		};
	});
	return _ensureMultiDayRangeSelected.apply(this, arguments);
}
//#endregion
exports.ensureMultiDayRangeSelected = ensureMultiDayRangeSelected;
