<?php
/**
 * File Path: includes/taxonomies/class-mbs-taxonomy-settings-notice.php
 *
 * Taxonomy Settings Notice
 *
 * Static helper that renders the info-banner and optional 'View ...' button
 * row on taxonomy term-edit screens. Consolidated from near-identical
 * implementations in MBS_Taxonomy_Series, MBS_Taxonomy_Universe, and
 * MBS_Taxonomy_Collection (DUP-003, Session 136).
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Renders the settings-notice block on taxonomy term-edit screens.
 *
 * @since 1.0.0
 */
class MBS_Taxonomy_Settings_Notice { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * Render the settings-notice row and optional 'View ...' button row.
	 *
	 * Outputs:
	 *   - An optional 'View ...' button linking to the front-end term page
	 *     (omitted when get_term_link() returns a WP_Error).
	 *   - An inline info notice pointing editors to the MBS settings tab
	 *     where the full term metadata lives.
	 *
	 * @param WP_Term $term                The term being edited.
	 * @param string  $tab_slug            Settings tab slug (e.g. 'series', 'universes').
	 * @param string  $view_label          Translated label for the View button.
	 * @param string  $notice_format       Translatable sprintf string; %s = settings link.
	 * @param string  $settings_link_label Translated label for the inline settings link.
	 * @return void
	 * @since 1.0.0
	 */
	public static function render(
		WP_Term $term,
		string  $tab_slug,
		string  $view_label,
		string  $notice_format,
		string  $settings_link_label
	): void {
		$settings_url = admin_url( 'admin.php?page=my-book-showroom-settings&tab=' . $tab_slug );
		$term_link    = get_term_link( $term );
		if ( ! is_wp_error( $term_link ) ) {
			?>
		<tr class="mbs-settings-view-row">
			<th scope="row"></th>
			<td style="padding-top:4px;">
				<a href="<?php echo esc_url( $term_link ); ?>"
				   class="button button-secondary button-small"
				   target="_blank"
				   rel="noopener noreferrer">
					<?php echo esc_html( $view_label ); ?>
				</a>
			</td>
		</tr>
			<?php
		}
		?>
		<tr class="mbs-settings-notice-row">
			<td colspan="2" style="padding-left:0;padding-right:0;">
				<div class="notice notice-info inline" style="margin:0;">
					<p>
						<?php
						echo wp_kses_post( sprintf(
							$notice_format,
							'<a href="' . esc_url( $settings_url ) . '">' . esc_html( $settings_link_label ) . '</a>'
						) );
						?>
					</p>
				</div>
			</td>
		</tr>
		<?php
	}
}
