<?php
/**
 * Paywall template: classic
 *
 * Displays payment options grouped by product in a classic grid layout.
 *
 * Vars passed in:
 * - int    $postgate_post_id           Post ID being locked
 * - array  $postgate_price_ids         Array of price IDs from products
 * - array  $postgate_price_options     Formatted product/price options (always grouped by product)
 * - string $postgate_default_price_id  Pre-selected price ID
 *
 * @package PostGate
 * @subpackage Templates
 * @since 1.0.0
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Get settings using centralized helper
$postgate_settings = PostGate_Template_Utils::get_paywall_settings();
?>
<div class="postgate-paywall postgate-paywall--classic" role="region"
	aria-label="<?php esc_attr_e( 'Paywall', 'postgate' ); ?>">

	<?php
	// Render header partial
	PostGate_Template_Utils::partial(
		'parts/paywall-header',
		[
			'badge' => $postgate_settings['badge'],
			'title' => $postgate_settings['title'],
			'description' => $postgate_settings['description'],
		]
	);

	// Render content before partial
	PostGate_Template_Utils::partial(
		'parts/paywall-content-before',
		[ 'content_before' => $postgate_settings['content_before'] ]
	);
	?>

	<div class="postgate-paywall__price-box">
		<?php if ( ! empty( $postgate_price_options ) ) : ?>
			<div class="postgate-paywall__options" role="radiogroup" aria-labelledby="postgate-price-options-label">
				<?php foreach ( $postgate_price_options as $postgate_option ) : ?>
					<div class="postgate-paywall__product-box"
						aria-labelledby="postgate-product-<?php echo esc_attr( $postgate_option['product_id'] ); ?>-name">
						<?php
						// Render product header
						PostGate_Template_Utils::partial(
							'parts/product-header',
							[
								'product_id' => $postgate_option['product_id'],
								'product_name' => $postgate_option['product_name'],
								'product_description' => $postgate_option['product_description'] ?? '',
							]
						);
						?>

						<div class="postgate-paywall__product-prices">
							<?php foreach ( $postgate_option['prices'] as $postgate_price ) : ?>
								<?php
								// Render individual price option - classic layout
								PostGate_Template_Utils::partial(
									'parts/price-option-classic',
									[
										'price' => $postgate_price,
										'default_price_id' => $postgate_default_price_id,
										'post_id' => $postgate_post_id,
										'product_default_id' => $postgate_option['default_price_id'] ?? '',
									]
								);
								?>
							<?php endforeach; ?>
						</div>
					</div>
				<?php endforeach; ?>
			</div>
		<?php else : ?>
			<?php PostGate_Template_Utils::partial( 'parts/paywall-empty-state' ); ?>
		<?php endif; ?>

		<div class="postgate-paywall__cta">
			<button class="postgate-paywall__button postgate-paywall__button--primary postgate-paywall__unlock-button"
				type="button">
				<span class="postgate-icon postgate-icon--lock" aria-hidden="true"></span>
				<?php echo esc_html( $postgate_settings['button_text'] ); ?>
			</button>
		</div>

		<?php
		// Render content after partial
		PostGate_Template_Utils::partial(
			'parts/paywall-content-after',
			[ 'content_after' => $postgate_settings['content_after'] ]
		);
		?>
	</div>

	<?php
	// Render secondary row partial
	PostGate_Template_Utils::partial(
		'parts/paywall-secondary-row',
		[
			'post_id' => $postgate_post_id,
			'login_text' => $postgate_settings['login_text'],
		]
	);
	?>
</div>