import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { getBookingTicketKey, getDefaultStartParam, getShopDiscountKey, rulesHooks } from "./utils/index.js";
import useEngineContext from "../../hooks/useEngineContext.js";
import { OsKeyProvider } from "./context/OsKeyContext.js";
import { IsActiveProvider } from "./context/IsActiveContext.js";
import { request } from "../../utils/index.js";
import { Provider, createStore } from "./miniRedux.js";
import ticketBooking_default$1 from "./components/ticketBooking/index.js";
import locales_default from "./locales.js";
import index from "./components/menuBar/index.js";
import dayjs from "dayjs";
import React, { useLayoutEffect, useMemo, useRef } from "react";
import { locales } from "@pisell/utils";
import { cloneDeep } from "lodash";
import { useLocalStorageState } from "ahooks";
import "./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: dayjs(),
			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: 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] = useLocalStorageState("pisell-ticket-booking-nav-key", { defaultValue: "ticket" });
	const bookingConfigParams = useMemo(() => {
		if (isShowMenuBar && activeNavKey === "food") return _objectSpread2(_objectSpread2({}, propsBookingConfigParams), {}, {
			sub_type: "food",
			source_type: "pos"
		});
		return propsBookingConfigParams;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsBookingConfigParams
	]);
	const isShowTimeBar = useMemo(() => {
		return isShowMenuBar && activeNavKey === "food" ? false : propsIsShowTimeBar;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsIsShowTimeBar
	]);
	const isShowFloatButtons = useMemo(() => {
		return isShowMenuBar && activeNavKey === "food" ? false : propsIsShowFloatButtons;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsIsShowFloatButtons
	]);
	const osKey = 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 = useMemo(() => {
		if (isShowMenuBar && activeNavKey === "food") return "sku-list-a5";
		return propsProductDisplayConfig;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsProductDisplayConfig
	]);
	const internalStoreRef = useRef(null);
	const storeRef = externalStoreRef !== null && externalStoreRef !== void 0 ? externalStoreRef : internalStoreRef;
	const context = useEngineContext();
	const { pisellos, pisellosAllModule, businessUtils } = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
	const { BookingTicket, ShopDiscountImpl } = pisellosAllModule || {};
	locales.init(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");
	useLayoutEffect(() => {
		request.setRequest(context.appHelper.utils.request);
	}, []);
	useMemo(() => {
		storeRef.current = createStore(_objectSpread2(_objectSpread2({}, cloneDeep(ticketBookingInitialState)), {}, {
			bookingConfigParams,
			productExtensionType
		}, editModeInitialState || {}));
	}, [
		bookingConfigParams,
		productExtensionType,
		editModeInitialState
	]);
	useMemo(() => {
		const bookingTicketModule = pisellos === null || pisellos === void 0 ? void 0 : pisellos.getModule(getBookingTicketKey(osKey));
		if (BookingTicket && !bookingTicketModule) {
			var _businessUtils$getApp;
			pisellos === null || pisellos === void 0 || pisellos.registerModule(new BookingTicket(getBookingTicketKey(osKey)), {
				initialState: {},
				otherParams: {
					cacheId: 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(getShopDiscountKey(osKey));
		if (ShopDiscountImpl && !shopDiscountModule) pisellos === null || pisellos === void 0 || pisellos.registerModule(new ShopDiscountImpl(getShopDiscountKey(osKey)), { otherParams: {
			platform: "shop",
			rules: { hooks: propsRulesHooks || rulesHooks }
		} });
	}, [osKey]);
	return /* @__PURE__ */ React.createElement("div", { className: "pisell-ticket-booking-wrapper" }, isShowMenuBar && /* @__PURE__ */ React.createElement(index, {
		activeNavKey,
		onNavChange: setActiveNavKey
	}), /* @__PURE__ */ React.createElement(IsActiveProvider, { isActive }, /* @__PURE__ */ React.createElement(OsKeyProvider, {
		osKey,
		businessCode: props === null || props === void 0 ? void 0 : props.businessCode
	}, /* @__PURE__ */ React.createElement(Provider, {
		store: storeRef.current,
		key: activeNavKey
	}, /* @__PURE__ */ React.createElement(ticketBooking_default$1, {
		onPrerenderComplete,
		productDisplayConfig,
		isShowTimeBar,
		isShowFloatButtons,
		secondaryScreenDisplay,
		bodyTopSlot
	})))));
};
//#endregion
export { ticketBooking_default as default, ticketBookingInitialState };
