/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { Children, isValidElement } from "react";
//#region src/components/Banner/utils.ts
/**
* Maps banner variants to button variants following the Figma spec.
* Secondary banner variants map to secondary button variants.
*/
const BANNER_TO_BUTTON_VARIANT = {
	primary: "brand",
	secondary: "brand",
	brand: "brand",
	"brand-secondary": "brand-secondary",
	alert: "alert",
	"alert-secondary": "alert-secondary",
	warning: "warning",
	"warning-secondary": "warning-secondary",
	success: "positive",
	"success-secondary": "positive-secondary",
	info: "info",
	"info-secondary": "info-secondary"
};
/**
* Checks whether a React element has a specific displayName.
* Handles both regular function components and forwardRef components
* (which have typeof type === 'object').
*/
function hasDisplayName(child, name) {
	if (!isValidElement(child)) return false;
	const type = child.type;
	return (typeof type === "function" || typeof type === "object" && type !== null) && "displayName" in type && type.displayName === name;
}
/**
* Separates Banner children into content (BannerContent) and action elements.
* Skips falsy children so conditional patterns like {show && <Button />} work.
*/
function separateChildren(children) {
	let content = null;
	const actions = [];
	Children.forEach(children, (child) => {
		if (child == null || child === false || child === true || child === "") return;
		if (hasDisplayName(child, "BannerContent")) content = child;
		else actions.push(child);
	});
	return {
		content,
		actions
	};
}
//#endregion
export { BANNER_TO_BUTTON_VARIANT, hasDisplayName, separateChildren };
