<?php
/**
 * File Path: templates/admin/dashboard-register.php
 *
 * Admin Dashboard — Registration Nudge + Feature Comparison (WO-002)
 *
 * Shown only for keyless installs and FREE-registered users.
 * Suppressed for PRO and Publisher tiers (checked by caller in dashboard.php).
 *
 * Contains:
 *   1. Registration nudge panel (keyless only) — benefit-driven, not scary
 *   2. Feature comparison table — tier matrix with Settings Import row
 *
 * @package MyBookShowroom
 * @since   1.3.0 (WO-002)
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variables injected by mbs_get_template_part(); not global vars

$_reg_is_keyless = mbs_is_keyless();
$_reg_license_url = admin_url( 'admin.php?page=my-book-showroom-settings&tab=license' );
?>

<?php if ( $_reg_is_keyless ) : ?>
<!-- ── Registration Nudge (keyless only) ────────────────────────────────── -->
<div class="mbs-dashboard-card mbs-register-nudge-card" style="margin-bottom:16px;border-left:4px solid #4AABB8;">
	<h2 style="margin-top:0;"><?php esc_html_e( 'Register Your Plugin (Optional)', 'my-book-showroom' ); ?></h2>
	<p style="margin:0 0 12px;">
		<?php esc_html_e( 'Registration is free and unlocks settings import/export, plus keeps you in the loop on updates. We will email your key instantly.', 'my-book-showroom' ); ?>
	</p>
	<p style="margin:0;display:flex;gap:12px;align-items:center;flex-wrap:wrap;">
		<a href="<?php echo esc_url( $_reg_license_url ); ?>"
		   class="button button-primary">
			<?php esc_html_e( 'Register now — it\'s free', 'my-book-showroom' ); // phpcs:ignore Squiz.Strings.ConcatenationSpacing ?>
		</a>
		<a href="<?php echo esc_url( MBS_PRIVACY_URL ); ?>"
		   target="_blank" rel="noopener noreferrer"
		   style="font-size:12px;color:#9AABBA;">
			<?php esc_html_e( 'Privacy policy', 'my-book-showroom' ); ?>
		</a>
	</p>
</div><!-- .mbs-register-nudge-card -->
<?php endif; ?>

<!-- ── Feature Comparison Table ─────────────────────────────────────────── -->
<div class="mbs-dashboard-card" style="margin-bottom:16px;">
	<h2 style="margin-top:0;"><?php esc_html_e( 'What\'s in each tier?', 'my-book-showroom' ); ?></h2>
	<?php
	$_reg_features = array(
		array( __( 'Book catalog display',                              'my-book-showroom' ), true,  true,  true  ),
		array( __( 'CSV / XLSX / ZIP import',                           'my-book-showroom' ), true,  true,  true  ),
		array( __( 'ISBN lookup — Google Books &amp; Open Library',     'my-book-showroom' ), true,  true,  true  ),
		array( __( 'ISBN lookup — Amazon PA-API',                       'my-book-showroom' ), false, true,  true  ),
		array( __( 'Export books as CSV or XLSX',                       'my-book-showroom' ), false, true,  true  ),
		array( __( 'Coming Soon badge &amp; pre-order link',            'my-book-showroom' ), false, true,  true  ),
		array( __( 'PRO display layouts (4)',                           'my-book-showroom' ), false, true,  true  ),
		array( __( 'Drag &amp; drop section order',                     'my-book-showroom' ), false, true,  true  ),
		array( __( '16 advanced color palettes',                        'my-book-showroom' ), false, true,  true  ),
		array( __( 'Custom CSS',                                        'my-book-showroom' ), false, true,  true  ),
		array( __( 'Global share text',                                 'my-book-showroom' ), false, true,  true  ),
		array( __( 'Settings import *',                                 'my-book-showroom' ), 'reg', true,  true  ),
		array( __( 'Sites allowed',                                     'my-book-showroom' ), '1',   '1',   '3'   ),
	);
	?>
	<table class="mbs-license-feature-table widefat striped">
		<thead>
			<tr>
				<th><?php esc_html_e( 'Feature', 'my-book-showroom' ); ?></th>
				<th class="mbs-lft-tier"><?php esc_html_e( 'FREE', 'my-book-showroom' ); ?></th>
				<th class="mbs-lft-tier"><?php esc_html_e( 'PRO', 'my-book-showroom' ); ?></th>
				<th class="mbs-lft-tier"><?php esc_html_e( 'Publisher', 'my-book-showroom' ); ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach ( $_reg_features as $row ) :
				list( $label, $free_val, $pro_val, $pub_val ) = $row;
				$_cell = function( $val ) {
					if ( true === $val )  return '<span class="mbs-lft-yes" aria-label="' . esc_attr__( 'Included', 'my-book-showroom' ) . '">&#10003;</span>';
					if ( false === $val ) return '<span class="mbs-lft-no"  aria-label="' . esc_attr__( 'Not included', 'my-book-showroom' ) . '">&#8212;</span>';
					if ( 'reg' === $val ) return '<span class="mbs-lft-yes mbs-lft-registered" aria-label="' . esc_attr__( 'With registration', 'my-book-showroom' ) . '">&#10003;</span>';
					return esc_html( $val );
				};
			?>
			<tr>
				<td><?php echo esc_html( $label ); ?></td>
				<td class="mbs-lft-tier"><?php echo wp_kses_post( $_cell( $free_val ) ); ?></td>
				<td class="mbs-lft-tier"><?php echo wp_kses_post( $_cell( $pro_val ) ); ?></td>
				<td class="mbs-lft-tier"><?php echo wp_kses_post( $_cell( $pub_val ) ); ?></td>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>
	<p class="description" style="font-size:11px;margin-top:8px;">
		* <?php
			printf(
				/* translators: %s: privacy policy link */
				esc_html__( 'Requires free registration. It\'s free, instant, and we will never spam you or sell your data. %s.', 'my-book-showroom' ),
				'<a href="' . esc_url( MBS_PRIVACY_URL ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Privacy policy', 'my-book-showroom' ) . '</a>'
			);
		?>
	</p>
	<?php if ( $_reg_is_keyless ) : ?>
	<p style="margin-top:12px;">
		<a href="<?php echo esc_url( $_reg_license_url ); ?>"
		   class="button button-primary">
			<?php esc_html_e( 'Get your free registration key →', 'my-book-showroom' ); ?>
		</a>
	</p>
	<?php endif; ?>
</div><!-- feature comparison card -->
