const SENSITIVE_HINTS = [
	'secret',
	'token',
	'password',
	'api_key',
	'apikey',
	'webhook',
];

export const REDACTED_PLACEHOLDER = 'Hidden for security';

export const isSensitiveKey = ( key: string ): boolean =>
	SENSITIVE_HINTS.some( ( hint ) => key.toLowerCase().includes( hint ) );

/**
 * One shared redaction helper. Returns the placeholder for sensitive contexts,
 * otherwise the original value as a string.
 * @param value
 * @param context
 */
export const redactDisplayValue = (
	value: unknown,
	context: 'sensitive' | 'plain' = 'plain'
): string => {
	if ( 'sensitive' === context ) {
		return REDACTED_PLACEHOLDER;
	}

	return 'string' === typeof value ? value : String( value ?? '' );
};
