<?php
/**
 * Recast Paywall - Block-level Paywall Template
 * 
 * This template can be overridden by copying it to:
 * yourtheme/recast-paywall/paywall-block.php
 * 
 * Variables available:
 * @var WP_Post $post Post object
 * @var int $postId Post ID
 * @var array $inventoryData Inventory data (item_id, price, status, currency)
 * @var array $userState User state (is_logged_in, user_id, user_email, user_name)
 * @var string $summary Content summary/teaser
 * @var \RecastPaywall\Frontend\PaywallRenderer $this Renderer instance
 * 
 * @package RecastPaywall
 * @version 1.0.0
 */

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

$price = $inventoryData['price'];
$currency = $inventoryData['currency'];

$priceDisplay = $price ? sprintf('%s', number_format($price)) : 'Free';
?>

<div class="recast-paywall-block" data-post-id="<?php echo esc_attr($postId); ?>">
    <div class="recast-paywall-block-content">
        <div class="recast-paywall-logo">
            <svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
                <path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
            </svg>
            <span><?php esc_html_e('Premium Content', 'recast-paywall'); ?></span>
        </div>
        
        <div class="recast-paywall-block-cta">
            <div class="recast-paywall-pricing">
                <div class="recast-paywall-price">
                    <?php echo esc_html($priceDisplay); ?>
                    <svg xmlns="http://www.w3.org/2000/svg" width="0.6em" height="0.6em" viewBox="0 0 21 22" role="img" class="" aria-hidden="true"><path fill="currentColor" fill-rule="nonzero" d="M0 12.497v9.168c0 .185.15.335.337.335H11.63c.09 0 .176-.036.239-.098l9.07-8.975a.167.167 0 0 0-.12-.285h-5.342a.168.168 0 0 0-.168.168v3.76a.168.168 0 0 1-.168.168H6.81a.168.168 0 0 1-.169-.167V6.663c0-.093.076-.168.169-.168h8.272a.17.17 0 0 1 .17.169v3.09c0 .093.075.168.168.168h5.413A.166.166 0 0 0 21 9.756V.166A.166.166 0 0 0 20.833 0h-8.392a.338.338 0 0 0-.237.097L.258 11.881a.865.865 0 0 0-.258.616"></path></svg>
                </div>
            </div>
            
            <div class="recast-paywall-actions">
                <?php if (!$userState['is_logged_in']): ?>
                    <div class="recast-paywall-login-prompt">
                        <p><?php esc_html_e('Please log in to purchase this content', 'recast-paywall'); ?></p>
                        <a href="<?php echo esc_url(wp_login_url(get_permalink($postId))); ?>" class="recast-paywall-button recast-paywall-button-primary">
                            <?php esc_html_e('Log In', 'recast-paywall'); ?>
                        </a>
                    </div>
                <?php else: ?>
                    <div class="recast-paywall-purchase">
                        <button class="recast-paywall-button recast-paywall-button-primary" onclick="recastPurchaseContent(<?php echo esc_js($postId); ?>, event)">
                            <?php 
                            /* translators: %s: Price display */
                            printf(esc_html__('Purchase for %s', 'recast-paywall'), esc_html($priceDisplay)); 
                            ?>
                            <svg xmlns="http://www.w3.org/2000/svg" width="0.6em" height="0.6em" viewBox="0 0 21 22" role="img" class="" aria-hidden="true"><path fill="currentColor" fill-rule="nonzero" d="M0 12.497v9.168c0 .185.15.335.337.335H11.63c.09 0 .176-.036.239-.098l9.07-8.975a.167.167 0 0 0-.12-.285h-5.342a.168.168 0 0 0-.168.168v3.76a.168.168 0 0 1-.168.168H6.81a.168.168 0 0 1-.169-.167V6.663c0-.093.076-.168.169-.168h8.272a.17.17 0 0 1 .17.169v3.09c0 .093.075.168.168.168h5.413A.166.166 0 0 0 21 9.756V.166A.166.166 0 0 0 20.833 0h-8.392a.338.338 0 0 0-.237.097L.258 11.881a.865.865 0 0 0-.258.616"></path></svg>
                        </button>
                        <p class="recast-paywall-note"><?php esc_html_e('One-time purchase', 'recast-paywall'); ?></p>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

