/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

const require_runtime = require('../../_virtual/_rolldown/runtime.js');
const require_devtools = require('../../global/js/utils/devtools.js');
const require_context = require('./context.js');
const require_Carousel = require('../Carousel/Carousel.js');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");

//#region src/components/InterstitialScreen/InterstitialScreenBody.tsx
/**
* Copyright IBM Corp. 2024, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
const InterstitialScreenBody = react.default.forwardRef((props, ref) => {
	const { className = "", contentRenderer, ...rest } = props;
	const bodyBlockClass = `${require_context.blockClass}--internal-body`;
	const [stepType, setStepType] = (0, react.useState)();
	const { setBodyChildrenData, bodyChildrenData, isFullScreen, setProgStep, bodyScrollRef, scrollRef, handleGotoStep, progStep, setStepCount, disableButtonConfig, setDisableButtonConfig } = (0, react.useContext)(require_context.InterstitialScreenContext);
	const [scrollPercent, setScrollPercent] = (0, react.useState)(-1);
	(0, react.useEffect)(() => {
		const _bodyContent = contentRenderer?.({
			handleGotoStep,
			progStep,
			disableActionButton
		}) ?? props.children;
		const children = (0, react.isValidElement)(_bodyContent) && _bodyContent.props.children != null ? _bodyContent.props.children : _bodyContent;
		const validChildren = react.default.Children.toArray(children).filter(react.isValidElement);
		if (validChildren.length > 1) {
			setStepType("multi");
			setStepCount?.(validChildren.length);
			setBodyChildrenData?.(validChildren);
		} else {
			setStepType("single");
			setStepCount?.(1);
			setBodyChildrenData?.(_bodyContent);
		}
	}, [
		props.children,
		contentRenderer,
		progStep
	]);
	(0, react.useEffect)(() => {
		if (scrollPercent !== -1) {
			const currentStep = scrollPercent / (bodyChildrenData && bodyChildrenData.length > 1 ? parseFloat((1 / (bodyChildrenData.length - 1)).toFixed(2)) : 0);
			setProgStep?.(Math.ceil(currentStep));
		}
	}, [scrollPercent]);
	const disableActionButton = (config) => {
		setDisableButtonConfig?.({
			...disableButtonConfig,
			...config
		});
	};
	const onScrollHandler = (scrollPercent) => setScrollPercent(scrollPercent);
	const renderBody = () => /* @__PURE__ */ react.default.createElement("div", {
		className: `${require_context.blockClass}--body ${className}`,
		ref: bodyScrollRef ?? ref,
		...require_devtools.getDevtoolsProps("InterstitialScreenBody"),
		...isFullScreen ? rest : {}
	}, /* @__PURE__ */ react.default.createElement("div", { className: `${require_context.blockClass}--content` }, stepType === "multi" ? /* @__PURE__ */ react.default.createElement("div", { className: `${require_context.blockClass}__carousel` }, /* @__PURE__ */ react.default.createElement(require_Carousel.Carousel, {
		disableArrowScroll: true,
		disableResetOnResize: true,
		ref: scrollRef,
		onScroll: onScrollHandler
	}, bodyChildrenData)) : stepType === "single" ? bodyChildrenData : ""));
	return isFullScreen ? renderBody() : /* @__PURE__ */ react.default.createElement(_carbon_react.ModalBody, {
		ref,
		className: bodyBlockClass,
		...rest
	}, renderBody());
});
InterstitialScreenBody.propTypes = {
	children: prop_types.default.node,
	className: prop_types.default.string,
	contentRenderer: prop_types.default.func
};

//#endregion
exports.default = InterstitialScreenBody;