const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.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 initialState = {
	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,
	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
};
const getTenantData = function() {
	var _ref = require_asyncToGenerator._asyncToGenerator(function* (shopId) {
		return require_index$1.request.getRequest().get(`/tenant/my-pisell/integration/${shopId}`, {}, { pisell2: true });
	});
	return function getTenantData(_x) {
		return _ref.apply(this, arguments);
	};
}();
var ticketBooking_default = (props) => {
	var _context$appHelper, _context$appHelper2, _context$appHelper2$g, _context$appHelper$ut, _context$appHelper$ut2, _context$appHelper$ut3, _context$appHelper$ut4, _context$appHelper$ut5, _context$appHelper$ut6;
	const { productExtensionType, bookingConfigParams: propsBookingConfigParams, isShowMenuBar = true, onPrerenderComplete, isShowTimeBar: propsIsShowTimeBar = true, isShowFloatButtons: propsIsShowFloatButtons = true, productDisplayConfig: propsProductDisplayConfig, isActive = true, rulesHooks: propsRulesHooks } = 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]);
	const productDisplayConfig = (0, react.useMemo)(() => {
		if (isShowMenuBar && activeNavKey === "food") return "sku-list-a5";
		return propsProductDisplayConfig;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsProductDisplayConfig
	]);
	const storeRef = (0, react.useRef)(null);
	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 || {};
	const [logo, setLogo] = (0, react.useState)("");
	const shopId = ((_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2$g = _context$appHelper2.getData) === null || _context$appHelper2$g === void 0 ? void 0 : _context$appHelper2$g.call(_context$appHelper2, "shop_id")) || ((_context$appHelper$ut = context.appHelper.utils.store) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut.getState) === 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.global) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.globalConfig) === null || _context$appHelper$ut2 === void 0 ? void 0 : _context$appHelper$ut2.id);
	(0, react.useEffect)(() => {
		getTenantData(shopId).then((res) => {
			var _res$data;
			if ((_res$data = res.data) === null || _res$data === void 0 || (_res$data = _res$data.tenant) === null || _res$data === void 0 ? void 0 : _res$data.logo) setLogo(res.data.tenant.logo);
		});
	}, []);
	_pisell_utils.locales.init(require_locales.default, ((_context$appHelper$ut3 = context.appHelper.utils) === null || _context$appHelper$ut3 === void 0 || (_context$appHelper$ut4 = _context$appHelper$ut3.getApp) === null || _context$appHelper$ut4 === void 0 || (_context$appHelper$ut4 = _context$appHelper$ut4.call(_context$appHelper$ut3)) === null || _context$appHelper$ut4 === void 0 || (_context$appHelper$ut4 = _context$appHelper$ut4.locales) === null || _context$appHelper$ut4 === void 0 || (_context$appHelper$ut5 = _context$appHelper$ut4.getLocale) === null || _context$appHelper$ut5 === void 0 ? void 0 : _context$appHelper$ut5.call(_context$appHelper$ut4)) || ((_context$appHelper$ut6 = context.appHelper.utils) === null || _context$appHelper$ut6 === void 0 || (_context$appHelper$ut6 = _context$appHelper$ut6.storage) === null || _context$appHelper$ut6 === void 0 ? void 0 : _context$appHelper$ut6.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)(initialState)), {}, {
			bookingConfigParams,
			productExtensionType
		}));
	}, [bookingConfigParams, productExtensionType]);
	(0, react.useMemo)(() => {
		if (BookingTicket) {
			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")
				}
			});
		}
		if (ShopDiscountImpl) 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,
		logoUrl: logo
	}), /* @__PURE__ */ react.default.createElement(require_IsActiveContext.IsActiveProvider, { isActive }, /* @__PURE__ */ react.default.createElement(require_OsKeyContext.OsKeyProvider, { osKey }, /* @__PURE__ */ react.default.createElement(require_miniRedux.Provider, {
		store: storeRef.current,
		key: activeNavKey
	}, /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		onPrerenderComplete,
		productDisplayConfig,
		isShowTimeBar,
		isShowFloatButtons
	})))));
};
//#endregion
exports.default = ticketBooking_default;
