/**
 * Utility functions for Cart Recovery
 *
 * @package EDD\Pro\CartRecovery\Admin
 */

/**
 * Normalizes a message from various input formats.
 *
 * @param {string|Object} input       - The input message or response object.
 * @param {Object}        messages    - The messages configuration object.
 * @param {string}        fallbackKey - The fallback message key.
 * @return {string} The normalized message string.
 */
export function normalizeMessage( input, messages, fallbackKey ) {
	if ( typeof input === 'string' ) {
		return input;
	}

	if ( input?.message && typeof input.message === 'string' ) {
		return input.message;
	}

	return messages?.[ fallbackKey ] || '';
}
