import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.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 from "./components/ticketBooking/index.js";
import locales_default from "./locales.js";
import index from "./components/menuBar/index.js";
import dayjs from "dayjs";
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } 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 initialState = {
	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,
	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
};
const getTenantData = function() {
	var _ref = _asyncToGenerator(function* (shopId) {
		return 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] = 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]);
	const productDisplayConfig = useMemo(() => {
		if (isShowMenuBar && activeNavKey === "food") return "sku-list-a5";
		return propsProductDisplayConfig;
	}, [
		isShowMenuBar,
		activeNavKey,
		propsProductDisplayConfig
	]);
	const storeRef = useRef(null);
	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 || {};
	const [logo, setLogo] = 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);
	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);
		});
	}, []);
	locales.init(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");
	useLayoutEffect(() => {
		request.setRequest(context.appHelper.utils.request);
	}, []);
	useMemo(() => {
		storeRef.current = createStore(_objectSpread2(_objectSpread2({}, cloneDeep(initialState)), {}, {
			bookingConfigParams,
			productExtensionType
		}));
	}, [bookingConfigParams, productExtensionType]);
	useMemo(() => {
		if (BookingTicket) {
			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")
				}
			});
		}
		if (ShopDiscountImpl) 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,
		logoUrl: logo
	}), /* @__PURE__ */ React.createElement(IsActiveProvider, { isActive }, /* @__PURE__ */ React.createElement(OsKeyProvider, { osKey }, /* @__PURE__ */ React.createElement(Provider, {
		store: storeRef.current,
		key: activeNavKey
	}, /* @__PURE__ */ React.createElement(TicketBooking, {
		onPrerenderComplete,
		productDisplayConfig,
		isShowTimeBar,
		isShowFloatButtons
	})))));
};
//#endregion
export { ticketBooking_default as default };
