<?php
/**
 * Client-facing administration notice copy helpers.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Admin;

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- scheduled_changes_ is the stable plugin prefix.

/**
 * Formats admin action notices without exposing raw exceptions to users.
 */
final class AdminNoticeMessages {
	/**
	 * Keeps the user notice client-facing and emits technical detail for tooling.
	 *
	 * @param string     $message Client-facing notice message.
	 * @param \Throwable $throwable Error returned by the failed action.
	 * @param string     $support_detail_label Label for the debug detail.
	 */
	public static function withSupportDetail( string $message, \Throwable $throwable, string $support_detail_label ): string {
		$detail = trim( $throwable->getMessage() );

		if ( '' !== $detail ) {
			do_action(
				'scheduled_changes_admin_action_notice_detail',
				rtrim( $support_detail_label, ':' ),
				$detail,
				$throwable
			);
		}

		return $message;
	}
}
