<?php
/**
 * Price Option - Classic Layout
 *
 * Displays a single price option in classic card-based layout.
 * Used within the classic 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
 */

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' : '';
?>

<label class="postgate-paywall__option<?php echo esc_attr( $postgate_selected_class ); ?>">
	<input type="radio" name="postgate_price_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-interval="<?php echo esc_attr( $price['interval'] ); ?>"
		data-currency="<?php echo esc_attr( $price['currency'] ); ?>"
		data-amount="<?php echo esc_attr( $price['amount_minor'] ); ?>"
		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>

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

		<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'] ) ) : ?>
				<?php
				$postgate_interval_class = 'postgate-paywall__price-interval';
				if ( ! empty( $price['interval_count'] ) && $price['interval_count'] > 1 ) {
					$postgate_interval_class .= ' has-count';
				}
				?>
				<span class="<?php echo esc_attr( $postgate_interval_class ); ?>">
					<?php echo esc_html( $price['interval_label'] ); ?>
				</span>
			<?php endif; ?>
		</span>
	</span>
</label>