<?php
/**
 * File Path: includes/admin/tabs/class-mbs-tab-shortcodes-render.php
 *
 * Add to Pages Tab — Render Class
 *
 * Delegates to template partials via mbs_get_template_part():
 *   templates/admin/shortcodes-card.php — receives $layouts + $is_pro
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Admin/Tabs
 * @since      1.0.0
 */

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

class MBS_Tab_Shortcodes_Render { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * Render the Add to Pages tab.
	 *
	 * @return void
	 */
	public static function render(): void {
		$is_pro  = mbs_is_pro();
		$layouts = MBS_Layout_Registry::get_layout_options();
		?>
		<div class="mbs-tab-shortcodes">

			<h2><?php esc_html_e( 'Add to Pages', 'my-book-showroom' ); ?></h2>
			<p class="mbs-settings-subtitle">
				<?php esc_html_e( 'Use these shortcodes to display your books on any page, post, or widget area. Configure the options, click Copy, then paste the snippet into your page.', 'my-book-showroom' ); ?>
			</p>

			<?php self::render_callout(); ?>

			<?php
			mbs_get_template_part(
				'admin/shortcodes-card',
				array(
					'layouts' => $layouts,
					'is_pro'  => $is_pro,
				)
			);
			?>

		</div>
		<?php

	}

	/**
	 * Render the dismissible how-to callout for the Add to Pages tab.
	 *
	 * Skipped entirely once the current user has dismissed it.
	 * Dismissal is persisted via mbs_dismissed_add_to_pages_callout user meta.
	 *
	 * @return void
	 */
	public static function render_callout(): void {
		if ( get_user_meta( get_current_user_id(), 'mbs_dismissed_add_to_pages_callout', true ) ) {
			return;
		}
		?>
		<div class="mbs-add-to-pages-callout" id="mbs-add-to-pages-callout">
			<button type="button" class="mbs-callout-dismiss"
			        data-nonce="<?php echo esc_attr( wp_create_nonce( 'mbs_dismiss_callout' ) ); ?>"
			        aria-label="<?php esc_attr_e( 'Dismiss this message', 'my-book-showroom' ); ?>">
				&times;
			</button>
			<p><strong><?php esc_html_e( 'How to show your books on a page — two steps', 'my-book-showroom' ); ?></strong></p>
			<ol>
				<li><?php esc_html_e( 'Configure what you want below, then click Copy.', 'my-book-showroom' ); ?></li>
				<li><?php esc_html_e( 'Paste the copied snippet into any page or post on your WordPress site.', 'my-book-showroom' ); ?></li>
			</ol>
			<p class="mbs-callout-tip">
				<?php esc_html_e( 'Using the block editor? Search for "Book" in the block inserter — your My Book Showroom blocks are ready to use there directly, no copy-paste needed.', 'my-book-showroom' ); ?>
			</p>
		</div>
		<?php
	}
}
