import useEngineContext from "../../hooks/useEngineContext.js";
import useWindowSize from "../../hooks/useWindowSize.js";
import { formatCurrentUser } from "./utils.js";
import { AppointmentBookingProvider } from "./context.js";
import { contextUtils, useAppointmentBooking } from "./hooks.js";
import Layout from "./components/Content/index.js";
import locales_default from "./locales.js";
import React, { useEffect, useMemo } from "react";
import { isIpad, isMobile, locales } from "@pisell/utils";
import "./index.less";
//#region src/components/appointmentBooking/index.tsx
const AppointmentBooking = () => {
	var _context$engine;
	const context = useEngineContext();
	locales.init(locales_default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
	useWindowSize({ debounceMs: 200 });
	const utils = contextUtils();
	const appointmentBooking = useAppointmentBooking();
	const isMobileLayout = useMemo(() => isMobile() && !isIpad(), []);
	useEffect(() => {
		var _appointmentBooking$o;
		const { bookingSubject } = (appointmentBooking === null || appointmentBooking === void 0 || (_appointmentBooking$o = appointmentBooking.otherParams) === null || _appointmentBooking$o === void 0 ? void 0 : _appointmentBooking$o.productModuleParams) || {};
		if ((bookingSubject === null || bookingSubject === void 0 ? void 0 : bookingSubject.type) === "form") return;
		appointmentBooking.getAccounts().then((data) => {
			if (!data.length) {
				const currentUser = formatCurrentUser(utils);
				appointmentBooking.addAccounts([currentUser]);
			} else if (data.length >= 1) {
				const meAccount = data === null || data === void 0 ? void 0 : data.find((d) => !(d === null || d === void 0 ? void 0 : d.isGuest));
				const currentUser = formatCurrentUser(utils);
				if (currentUser && meAccount.id !== currentUser.id) appointmentBooking.setLoginAccount(meAccount.id, currentUser);
			}
		});
	}, []);
	return /* @__PURE__ */ React.createElement("div", { className: `parallel-booking-wrap ${isMobileLayout ? "parallel-booking-mobile-wrap" : ""}` }, /* @__PURE__ */ React.createElement(AppointmentBookingProvider, null, /* @__PURE__ */ React.createElement(Layout, null)));
};
//#endregion
export { AppointmentBooking as default };
