<?php
/**
 * Price Option - Compact Layout
 *
 * Displays a single price option in compact inline layout with per-option buttons.
 * Used within the compact paywall template for individual price selections.
 *
 * @package PostGate
 * @subpackage Templates/Parts
 * @since 1.0.1
 *
 * @var array  $price               Price data array
 * @var string $default_price_id    Default selected price ID
 * @var int    $post_id             Current post ID
 * @var string $product_default_id  Product's default price ID
 * @var string $button_text         Unlock button text
 */

defined( 'ABSPATH' ) || exit;

// Determine if this price should be checked
$postgate_is_checked = ( $price['id'] === $default_price_id ) ||
	( $price['id'] === $product_default_id && empty( $default_price_id ) );
$postgate_selected_class = $postgate_is_checked ? ' is-selected' : '';
$postgate_price_data_id = 'postgate-price-' . esc_attr( $price['id'] );
?>

<div class="postgate-paywall__option<?php echo esc_attr( $postgate_selected_class ); ?>"
	data-price-id="<?php echo esc_attr( $price['id'] ); ?>">

	<label class="postgate-paywall__option__label" for="<?php echo esc_attr( $postgate_price_data_id ); ?>">
		<input type="radio" name="postgate_price_id" id="<?php echo esc_attr( $postgate_price_data_id ); ?>"
			class="postgate-paywall__price-radio" value="<?php echo esc_attr( $price['id'] ); ?>" <?php checked( $postgate_is_checked ); ?> data-payment-type="<?php echo esc_attr( $price['type'] ); ?>"
			data-product-id="<?php echo esc_attr( $price['product_id'] ?? '' ); ?>"
			data-post-id="<?php echo esc_attr( $post_id ); ?>"
			aria-label="<?php echo esc_attr( $price['aria_label'] ); ?>" />

		<span class="postgate-paywall__price-content">
			<span class="postgate-paywall__price-type-large">
				<?php echo esc_html( $price['type_label'] ); ?>
			</span>

			<span class="postgate-paywall__price-amount" data-currency="<?php echo esc_attr( $price['currency'] ); ?>"
				data-amount="<?php echo esc_attr( $price['amount_minor'] ); ?>">
				<?php echo esc_html( $price['amount_locale'] ); ?>
				<?php if ( ! empty( $price['interval_label'] ) ) : ?>
					<span class="postgate-paywall__price-interval">
						<?php echo esc_html( $price['interval_label'] ); ?>
					</span>
				<?php endif; ?>
			</span>

			<?php if ( ! empty( $price['nickname'] ) ) : ?>
				<span class="postgate-paywall__price-description">
					<?php echo esc_html( $price['nickname'] ); ?>
				</span>
			<?php endif; ?>
		</span>
	</label>

	<span class="postgate-paywall__price-cta" aria-hidden="true">
		<button class="postgate-paywall__button postgate-paywall__button--primary postgate-paywall__unlock-button"
			type="button" data-for-price="<?php echo esc_attr( $price['id'] ); ?>">
			<span class="postgate-icon postgate-icon--lock" aria-hidden="true"></span>
			<?php echo esc_html( $button_text ); ?>
		</button>
	</span>
</div>