import { Children, isValidElement } from 'react';
import { getKey } from '@graphprotocol/gds-utils';
import { reactNodeToString } from "./reactNodeToString.js";
/**
 * Generates a stable key for a `ReactNode`. Useful for detecting when arbitrary content has
 * meaningfully changed.
 *
 * @param reactNode - Any React node (element, string, number, array, etc.)
 * @returns A string key that uniquely identifies the node structure and content.
 */
export function getReactNodeKey(reactNode) {
    const keys = Children.map(reactNode, (child) => {
        if (!child || typeof child === 'boolean') {
            return 'empty';
        }
        if (!isValidElement(child)) {
            return getKey(child);
        }
        if (child.key !== null) {
            return `key:${child.key}`;
        }
        return `${getKey(child.type)}:${reactNodeToString(child)}`;
    }) ?? [];
    return keys.length > 0 ? keys.join('|') : 'empty';
}
//# sourceMappingURL=getReactNodeKey.js.map