import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import PcModal from "../PcModal/index.js";
import React, { useEffect, useRef } from "react";
import classNames from "classnames";
import "./index.less";
//#region src/components/pisellModal/components/MobileModal/index.tsx
let modalCount = 0;
const MobileModal = (props) => {
	const { wrapClassName, mobileModalHeight } = props;
	const ref = React.useRef(null);
	const prevOpenRef = useRef(props.open);
	const isFirstRender = useRef(true);
	useEffect(() => {
		if (isFirstRender.current && props.open) {
			modalCount++;
			document.body.style.overflow = "hidden";
		}
		isFirstRender.current = false;
	}, []);
	useEffect(() => {
		if (!isFirstRender.current && props.open !== prevOpenRef.current) {
			if (props.open) {
				modalCount++;
				document.body.style.overflow = "hidden";
			} else {
				modalCount--;
				if (modalCount <= 0) {
					modalCount = 0;
					document.body.style.overflow = "";
				}
			}
			prevOpenRef.current = props.open;
		}
	}, [props.open]);
	useEffect(() => {
		return () => {
			if (prevOpenRef.current) {
				modalCount--;
				if (modalCount <= 0) {
					modalCount = 0;
					document.body.style.overflow = "";
				}
			}
		};
	}, []);
	return /* @__PURE__ */ React.createElement(PcModal, _objectSpread2(_objectSpread2({}, props), {}, {
		transitionName: "pisell-move-down",
		width: "100%",
		wrapClassName: classNames("pisell-mobile-modal", { [wrapClassName]: wrapClassName }),
		modalRender: (node) => {
			return /* @__PURE__ */ React.createElement("div", {
				className: classNames({ ["pisell-mobile-modal-render"]: mobileModalHeight }),
				style: { height: mobileModalHeight || "100%" },
				ref
			}, node);
		}
	}));
};
//#endregion
export { MobileModal as default };
