import { getLocale } from "../../../utils/locales.js";
import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import locales_default from "../locales.js";
import { isDayBooking, isEventBooking, isTerminalDayBooking } from "./service2/utils.js";
import { findNextDuration, flexibleObj, formatResource, getErrorList, request, sliceDayIntoFiveMinutes } from "../utils.js";
import { Context, Provider } from "./model.js";
import client_default from "./client/index.js";
import useEngineContext from "../../../hooks/useEngineContext.js";
import TabPane from "../components/tabPane/index.js";
import Footer from "../components/footer/index.js";
import Pet from "./pet/index.js";
import DateCom, { updateServiceDate } from "./date/index.js";
import header from "./header/index.js";
import Notes from "./notes/index.js";
import useCreateBookingPageHeader from "../hooks/useCreateBookingPageHeader.js";
import ContactInfoMode from "../info2/service/contactInfoMode/index.js";
import service_default from "./service/index.js";
import { Service2Cart } from "./service2/index.js";
import React, { useContext, useEffect, useMemo } from "react";
import { Skeleton } from "antd";
import { locales } from "@pisell/utils";
import classNames from "classnames";
import "./index.less";
//#region src/components/booking/info/main.tsx
const defaultModules = {
	client: 1,
	date: 1,
	service: 1,
	holder: 1,
	note: 1,
	service2: 0
};
locales.init(locales_default, getLocale());
const Info = Provider((props) => {
	var _modal$state2, _modal$state3, _modal$state4, _modal$state5;
	const { style, globalState, modules = defaultModules, slot } = props;
	const modal = useContext(Context);
	const context = useEngineContext();
	request.setRequest(context.appHelper.utils.request);
	const params = useMemo(() => {
		var _modal$state;
		return ((_modal$state = modal.state) === null || _modal$state === void 0 || (_modal$state = _modal$state.bookingConfig) === null || _modal$state === void 0 || (_modal$state = _modal$state.config) === null || _modal$state === void 0 || (_modal$state = _modal$state.basic) === null || _modal$state === void 0 ? void 0 : _modal$state.appointment_subject) || {};
	}, [(_modal$state2 = modal.state) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.bookingConfig) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.config) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.basic) === null || _modal$state2 === void 0 ? void 0 : _modal$state2.appointment_subject]);
	const { createHeader, isBookingCreatePage, isBookingCreatePageCreateMode } = useCreateBookingPageHeader(globalState);
	useEffect(() => {
		document.body.id = "body";
		if (props.setState) props.setState({ bookingFunctions: {
			formatResource,
			getErrorList,
			sliceDayIntoFiveMinutes,
			findNextDuration,
			flexibleObj,
			updateServiceDate
		} });
	}, []);
	useEffect(() => {
		var _context$appHelper, _context$appHelper$ge, _context$appHelper2, _context$appHelper2$i, _context$appHelper3;
		const isFranchisee = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.businessUtils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getAppByModal) === null || _context$appHelper$ge === void 0 ? void 0 : _context$appHelper$ge.call(_context$appHelper, "franchisee");
		modal.dispatch({
			type: "setState",
			payload: _objectSpread2(_objectSpread2({ setGlobalState: props.setGlobalState }, globalState), {}, {
				isTerminal: context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2$i = _context$appHelper2.isTerminal) === null || _context$appHelper2$i === void 0 ? void 0 : _context$appHelper2$i.call(_context$appHelper2),
				isFranchisee,
				timezone: context === null || context === void 0 || (_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.utils) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.store) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.getState()) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.global) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.globalConfig) === null || _context$appHelper3 === void 0 ? void 0 : _context$appHelper3.timezone,
				isDayBooking: (globalState === null || globalState === void 0 ? void 0 : globalState.renderType) === "dayBooking"
			})
		});
	}, [globalState]);
	const header$1 = useMemo(() => {
		if ((globalState === null || globalState === void 0 ? void 0 : globalState.renderType) === "eventBooking") return locales.getText("pisell2.text.enroll.detail");
		return (globalState === null || globalState === void 0 ? void 0 : globalState.bookingId) ? /* @__PURE__ */ React.createElement(header, {
			state: modal.state,
			dispatch: modal.dispatch
		}) : /* @__PURE__ */ React.createElement("div", {
			className: "",
			style: { height: 0 }
		});
	}, [
		globalState === null || globalState === void 0 ? void 0 : globalState.bookingId,
		modal.state,
		modal.dispatch,
		globalState === null || globalState === void 0 ? void 0 : globalState.renderType
	]);
	const notes = useMemo(() => {
		if (!modules.note) return null;
		if (isEventBooking(modal.state)) return null;
		if (isDayBooking(globalState)) return null;
		return (globalState === null || globalState === void 0 ? void 0 : globalState.bookingId) ? globalState.renderType === "eventBooking" || globalState.isBookingCreatePage ? /* @__PURE__ */ React.createElement(Notes, null) : null : null;
	}, [
		modules.note,
		globalState === null || globalState === void 0 ? void 0 : globalState.bookingId,
		globalState.render,
		(_modal$state3 = modal.state) === null || _modal$state3 === void 0 || (_modal$state3 = _modal$state3.notes) === null || _modal$state3 === void 0 ? void 0 : _modal$state3.orderNote
	]);
	return /* @__PURE__ */ React.createElement(React.Fragment, null, !!modal.state.setGlobalState ? /* @__PURE__ */ React.createElement(TabPane, {
		style: _objectSpread2(_objectSpread2({}, style), {}, { height: "100%" }),
		header: header$1,
		footer: /* @__PURE__ */ React.createElement(Footer, {
			state: modal.state,
			dispatch: modal.dispatch,
			source: "info"
		}),
		bodyClassName: classNames("booking-info-warp", {
			["create-booking-page-info-wrap"]: isBookingCreatePage,
			["create-booking-page-info-wrap-create"]: isBookingCreatePageCreateMode && !isTerminalDayBooking(modal.state)
		}),
		state: modal.state,
		dispatch: modal.dispatch,
		source: "info"
	}, /* @__PURE__ */ React.createElement("div", { className: "booking-info" }, createHeader, modules.client ? /* @__PURE__ */ React.createElement(client_default, null) : null, (modal === null || modal === void 0 || (_modal$state4 = modal.state) === null || _modal$state4 === void 0 || (_modal$state4 = _modal$state4.bookingConfig) === null || _modal$state4 === void 0 || (_modal$state4 = _modal$state4.config) === null || _modal$state4 === void 0 || (_modal$state4 = _modal$state4.cart_settings_tab) === null || _modal$state4 === void 0 || (_modal$state4 = _modal$state4.display_contact_info) === null || _modal$state4 === void 0 ? void 0 : _modal$state4.show_contact_info) === true ? /* @__PURE__ */ React.createElement(ContactInfoMode, null) : null, modules.holder && !((_modal$state5 = modal.state) === null || _modal$state5 === void 0 ? void 0 : _modal$state5.disabledEdit) ? /* @__PURE__ */ React.createElement(React.Fragment, null, params.type === "form" ? /* @__PURE__ */ React.createElement(Pet, null) : null) : null, modules.date ? /* @__PURE__ */ React.createElement(DateCom, null) : null, /* @__PURE__ */ React.createElement(Skeleton, {
		loading: globalState.loading,
		round: true,
		active: true,
		avatar: false,
		style: { paddingTop: 20 }
	}, modules.service ? /* @__PURE__ */ React.createElement(React.Fragment, null, modal.state.date.value ? /* @__PURE__ */ React.createElement(service_default, null) : null) : null, modules.service2 ? /* @__PURE__ */ React.createElement(React.Fragment, null, modal.state.date.value ? /* @__PURE__ */ React.createElement(Service2Cart, null) : null) : null, notes, slot ? slot : null))) : null);
});
//#endregion
export { Info as default };
