const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_index = require("./utils/index.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_OsKeyContext = require("./context/OsKeyContext.js");
const require_IsActiveContext = require("./context/IsActiveContext.js");
const require_index$1 = require("../../utils/index.js");
const require_miniRedux = require("./miniRedux.js");
const require_index$2 = require("./components/ticketBooking/index.js");
const require_locales = require("./locales.js");
const require_index$3 = require("./components/menuBar/index.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 lodash = require("lodash");
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/ticketBooking/index.tsx
const ticketBookingInitialState = {
	amountSymbol: "$",
	modalState: {
		client: {
			showModal: false,
			clients: [],
			value: {
				id: 0,
				nickname: "Select a customer"
			},
			clientsParams: {
				skip: 1,
				num: 100,
				search: ""
			},
			edit: false
		},
		date: {
			value: (0, dayjs.default)(),
			edit: false
		},
		service: {
			addModal: false,
			editModal: false,
			reloadResourceModal: false,
			services: [],
			resources: [],
			value: [],
			cacheItem: null,
			edit: false
		},
		pet: {
			showModal: false,
			pets: [],
			value: {},
			edit: false
		},
		addons: {
			showModal: false,
			value: [],
			productList: [],
			originData: [],
			edit: false,
			load: false
		},
		form: {
			value: {},
			forms: [],
			edit: false
		},
		notes: {
			orderNote: "",
			internalNotes: [],
			edit: false
		},
		disabledEdit: false,
		channelDisabledEdit: false,
		appointment_status: "new",
		eventOtherParams: void 0
	},
	bookingConfig: null,
	associated_menu_list_ids: void 0,
	bookingDetail: null,
	bookingId: 0,
	loading: false,
	open: false,
	isShowDeposit: false,
	activeKey: "info",
	exitModal: false,
	rebookState: {
		open: false,
		date: "2024-03-13 18:00"
	},
	bookingFunctions: {},
	eventOpen: false,
	renderType: "booking",
	openRebook: false,
	disableEventBookingEdit: false,
	isShowInfo: false,
	persistent: true,
	intervalSetTime: true,
	isTimeChange: false,
	isDateChange: false,
	list: {
		isLoading: false,
		bookingList: [],
		params: {
			["with"]: [
				"order",
				"order.customer",
				"contacts",
				"item",
				"appointmentForm.formRecord",
				"holder.formRecord"
			],
			booking_time_start_between: require_index.getDefaultStartParam(),
			child_booking: 1,
			skip: 1,
			num: 1e3
		},
		showList: [],
		listSelectType: "all",
		search: "",
		sort: ""
	},
	confirmOpen: false,
	createCount: 0,
	verticalAddServiceKey: 0,
	currentProduct: null,
	bookingConfigParams: { item_type: "appointment_booking" },
	productExtensionType: [
		"appointment_ticket",
		"session_ticket",
		"product_appointment",
		"service_product",
		"session_product",
		"normal",
		"product_appointment"
	],
	isParallelResourcesBooking: null,
	isEditTicketMode: false,
	paymentPaid: { value: {
		paidAmount: 0,
		paidAmountWithoutSurcharge: 0
	} }
};
var ticketBooking_default = (props) => {
	var _context$appHelper, _context$appHelper$ut, _context$appHelper$ut2, _context$appHelper$ut3, _context$appHelper$ut4;
	const { productExtensionType, bookingConfigParams: propsBookingConfigParams, isShowMenuBar = true, onPrerenderComplete, isShowTimeBar: propsIsShowTimeBar = true, isShowFloatButtons: propsIsShowFloatButtons = true, productDisplayConfig: propsProductDisplayConfig, isActive = true, rulesHooks: propsRulesHooks, storeRef: externalStoreRef, editModeInitialState, secondaryScreenDisplay, bodyTopSlot } = props;
	const [activeNavKey, setActiveNavKey] = (0, ahooks.useLocalStorageState)("pisell-ticket-booking-nav-key", { defaultValue: "ticket" });
	const bookingConfigParams = (0, react.useMemo)(() => {
		if (isShowMenuBar && activeNavKey === "food") return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, propsBookingConfigParams), {}, {
			sub_type: "food",
			source_type: "pos"
		});
		return propsBookingConfigParams;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsBookingConfigParams
	]);
	const isShowTimeBar = (0, react.useMemo)(() => {
		return isShowMenuBar && activeNavKey === "food" ? false : propsIsShowTimeBar;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsIsShowTimeBar
	]);
	const isShowFloatButtons = (0, react.useMemo)(() => {
		return isShowMenuBar && activeNavKey === "food" ? false : propsIsShowFloatButtons;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsIsShowFloatButtons
	]);
	const osKey = (0, react.useMemo)(() => {
		return `${bookingConfigParams === null || bookingConfigParams === void 0 ? void 0 : bookingConfigParams.sub_type}${(bookingConfigParams === null || bookingConfigParams === void 0 ? void 0 : bookingConfigParams.osKey) ? `-${bookingConfigParams === null || bookingConfigParams === void 0 ? void 0 : bookingConfigParams.osKey}` : ""}`;
	}, [bookingConfigParams]);
	const productDisplayConfig = (0, react.useMemo)(() => {
		if (isShowMenuBar && activeNavKey === "food") return "sku-list-a5";
		return propsProductDisplayConfig;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsProductDisplayConfig
	]);
	const internalStoreRef = (0, react.useRef)(null);
	const storeRef = externalStoreRef !== null && externalStoreRef !== void 0 ? externalStoreRef : internalStoreRef;
	const context = require_useEngineContext.default();
	const { pisellos, pisellosAllModule, businessUtils } = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
	const { BookingTicket, ShopDiscountImpl } = pisellosAllModule || {};
	_pisell_utils.locales.init(require_locales.default, ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut.getApp) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.call(_context$appHelper$ut)) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.locales) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut3 = _context$appHelper$ut2.getLocale) === null || _context$appHelper$ut3 === void 0 ? void 0 : _context$appHelper$ut3.call(_context$appHelper$ut2)) || ((_context$appHelper$ut4 = context.appHelper.utils) === null || _context$appHelper$ut4 === void 0 || (_context$appHelper$ut4 = _context$appHelper$ut4.storage) === null || _context$appHelper$ut4 === void 0 ? void 0 : _context$appHelper$ut4.get("umi_locale")) || "en");
	(0, react.useLayoutEffect)(() => {
		require_index$1.request.setRequest(context.appHelper.utils.request);
	}, []);
	(0, react.useMemo)(() => {
		storeRef.current = require_miniRedux.createStore(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, (0, lodash.cloneDeep)(ticketBookingInitialState)), {}, {
			bookingConfigParams,
			productExtensionType
		}, editModeInitialState || {}));
	}, [
		bookingConfigParams,
		productExtensionType,
		editModeInitialState
	]);
	(0, react.useMemo)(() => {
		const bookingTicketModule = pisellos === null || pisellos === void 0 ? void 0 : pisellos.getModule(require_index.getBookingTicketKey(osKey));
		if (BookingTicket && !bookingTicketModule) {
			var _businessUtils$getApp;
			pisellos === null || pisellos === void 0 || pisellos.registerModule(new BookingTicket(require_index.getBookingTicketKey(osKey)), {
				initialState: {},
				otherParams: {
					cacheId: require_index.getBookingTicketKey(osKey),
					platform: "shop",
					isFranchisee: businessUtils === null || businessUtils === void 0 || (_businessUtils$getApp = businessUtils.getAppByModal) === null || _businessUtils$getApp === void 0 ? void 0 : _businessUtils$getApp.call(businessUtils, "franchisee")
				}
			});
		}
		const shopDiscountModule = pisellos === null || pisellos === void 0 ? void 0 : pisellos.getModule(require_index.getShopDiscountKey(osKey));
		if (ShopDiscountImpl && !shopDiscountModule) pisellos === null || pisellos === void 0 || pisellos.registerModule(new ShopDiscountImpl(require_index.getShopDiscountKey(osKey)), { otherParams: {
			platform: "shop",
			rules: { hooks: propsRulesHooks || require_index.rulesHooks }
		} });
	}, [osKey]);
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-ticket-booking-wrapper" }, isShowMenuBar && /* @__PURE__ */ react.default.createElement(require_index$3.default, {
		activeNavKey,
		onNavChange: setActiveNavKey
	}), /* @__PURE__ */ react.default.createElement(require_IsActiveContext.IsActiveProvider, { isActive }, /* @__PURE__ */ react.default.createElement(require_OsKeyContext.OsKeyProvider, {
		osKey,
		businessCode: props === null || props === void 0 ? void 0 : props.businessCode
	}, /* @__PURE__ */ react.default.createElement(require_miniRedux.Provider, {
		store: storeRef.current,
		key: activeNavKey
	}, /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		onPrerenderComplete,
		productDisplayConfig,
		isShowTimeBar,
		isShowFloatButtons,
		secondaryScreenDisplay,
		bodyTopSlot
	})))));
};
//#endregion
exports.default = ticketBooking_default;
exports.ticketBookingInitialState = ticketBookingInitialState;
