/**
 * 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.
 */

import { __toESM } from "../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../node_modules/classnames/index.js";
import { pkg } from "../../settings.js";
import { getDevtoolsProps } from "../../global/js/utils/devtools.js";
import React, { forwardRef } from "react";
import PropTypes from "prop-types";
import { Grid } from "@carbon/react";

//#region src/components/Cascade/Cascade.tsx
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--cascade`;
const componentName = "Cascade";
const defaults = { grid: false };
/**

This pattern is intended for use with cards, tiles, or similarly styled
components. Use this patterns in areas that are the primary focus on the page to
help the user along their journey or locate the most important information on
the page. It should not be used on a page if it is the secondary focus of the
page as that will distract the user.

*/
const Cascade = forwardRef((props, ref) => {
	const { children, className, grid = defaults.grid, ...rest } = props;
	const childProps = {
		...rest,
		className: (0, import_classnames.default)(blockClass, className),
		ref,
		...getDevtoolsProps(componentName)
	};
	const modifyChildren = (child) => {
		const className = (0, import_classnames.default)(child.props.className, `${blockClass}__element`);
		return React.cloneElement(child, { className });
	};
	const getModifiedChildren = () => {
		return React.Children.map(children, (child) => modifyChildren(child));
	};
	if (grid) {
		let colIdx = 0;
		const gridElm = React.Children.map(children, (row) => {
			if (React.isValidElement(row)) {
				const cols = React.Children.map(row?.props.children, (col) => {
					if (React.isValidElement(col)) {
						colIdx = colIdx + 1;
						const colClassnames = (0, import_classnames.default)(col.props.className, `${blockClass}__col`, `${blockClass}__col-${colIdx}`);
						return React.cloneElement(col, { className: colClassnames });
					}
				});
				return React.cloneElement(row, { children: cols });
			}
			return children;
		});
		return /* @__PURE__ */ React.createElement("div", childProps, /* @__PURE__ */ React.createElement(Grid, null, gridElm));
	}
	return /* @__PURE__ */ React.createElement("div", childProps, getModifiedChildren());
});
Cascade.displayName = componentName;
Cascade.propTypes = {
	children: PropTypes.node,
	className: PropTypes.string,
	grid: PropTypes.bool
};

//#endregion
export { Cascade };