<?php

/**
 * The template for displaying the player paywall
 *
 * This template can be overridden by copying it to yourtheme/movie-engine/global/paywall.php.
 *
 * @package MovieEngine
 * @version 1.0.0
 */

if (! defined("ABSPATH")) {
    exit; // Exit if accessed directly
}

$post_id = $args['post_id'] ?? 0;
$title   = $args['title'] ?? esc_html__('Premium Content', 'cine-movie-engine');
$message = $args['message'] ?? esc_html__('Please subscribe to watch this content.', 'cine-movie-engine');
$btn_text = $args['btn_text'] ?? esc_html__('Subscribe Now', 'cine-movie-engine');
$btn_url  = $args['btn_url'] ?? '';
$ppv      = $args['ppv'] ?? ['sale_price' => 0, 'rent_price' => 0, 'rent_duration' => 48, 'currency' => '$'];
?>
<div class="movie-engine-player-wrapper me-paywall-container" data-post-id="<?php echo esc_attr($post_id); ?>" data-gramm="false" data-gramm_editor="false" data-enable-grammarly="false">
    <div class="movie-engine-paywall-inner me-paywall-inner">
        <div class="movie-engine-paywall-content me-paywall-content">
            <span class="dashicons dashicons-lock me-paywall-icon"></span>
            <h2 class="me-paywall-title"><?php echo esc_html($title); ?></h2>
            <p class="me-paywall-message"><?php echo \MovieEngine\Utils\Helpers::kses_post($message); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_post sanitizes HTML ?></p>

            <div class="movie-engine-paywall-actions me-paywall-actions">
                <?php if ($btn_url): ?>
                    <a href="<?php echo esc_url($btn_url); ?>" class="movie-engine-btn me-btn-primary me-btn-lg">
                        <?php echo esc_html($btn_text); ?>
                    </a>
                <?php endif; ?>

                <?php if (!empty($ppv['sale_price'])): ?>
                    <button type="button" class="movie-engine-btn-buy me-btn-buy">
                        <?php echo esc_html(sprintf(
                            /* translators: 1: currency symbol, 2: price */
                            __('Buy for %1$s%2$s', 'cine-movie-engine'),
                            $ppv['currency'] ?? '$',
                            $ppv['sale_price']
                        )); ?>
                    </button>
                <?php endif; ?>

                <?php if (!empty($ppv['rent_price'])): ?>
                    <button type="button" class="movie-engine-btn-rent me-btn-rent">
                        <?php
                        $hours = $ppv['rent_duration'];
                        $time_label = ($hours >= 24) ? sprintf(
                            /* translators: %d: number of days */
                            __('%d Days', 'cine-movie-engine'),
                            ceil($hours / 24)
                        ) : sprintf(
                            /* translators: %d: number of hours */
                            __('%d Hours', 'cine-movie-engine'),
                            $hours
                        );
                        echo esc_html(sprintf(
                            /* translators: 1: currency symbol, 2: price, 3: duration (e.g. 24 Hours) */
                            __('Rent for %1$s%2$s (%3$s)', 'cine-movie-engine'),
                            $ppv['currency'] ?? '$',
                            $ppv['rent_price'],
                            $time_label
                        ));
                        ?>
                    </button>
                <?php endif; ?>
            </div>

            <div class="me-mt-30">
                <a href="<?php echo esc_url(\MovieEngine\Payments\Membership::get_login_url(get_permalink($post_id))); ?>" class="me-link-muted">
                    <?php esc_html_e('Already have an account? Login', 'cine-movie-engine'); ?>
                </a>
            </div>
        </div>
    </div>
</div>