<?php
/**
 * Public subscription plans display.
 *
 * @since      1.0.0
 * @package    Subscription_System
 */

// If this file is called directly, abort.
if (!defined('ABSPATH')) {
    exit;
}

// Get currency symbol
$currency_symbols = array(
    'USD' => '$',
    'EUR' => '€',
    'GBP' => '£',
    'JPY' => '¥',
    'AUD' => '$',
    'CAD' => '$'
);

$settings = get_option('ss_settings', array(
    'currency' => 'USD',
    'currency_position' => 'before'
));

$currency_symbol = isset($currency_symbols[$settings['currency']]) ? $currency_symbols[$settings['currency']] : $settings['currency'];

// Format price with currency
function ss_format_price($price, $currency_symbol, $position = 'before') {
    if ($position === 'before') {
        return $currency_symbol . $price;
    } else {
        return $price . $currency_symbol;
    }
}
?>

<div class="ss-plans-container">
    <?php foreach ($plans as $plan_id => $plan) : ?>
        <div class="ss-plan">
            <div class="ss-plan-header">
                <h3 class="ss-plan-title"><?php echo esc_html($plan['name']); ?></h3>
                <div class="ss-plan-price">
                    <?php echo esc_html(ss_format_price($plan['price'], $currency_symbol, $settings['currency_position'])); ?>
                </div>
                <div class="ss-plan-duration">
                    <?php
                    if ($plan['duration'] > 0) {
                        // translators: %d is the number of days for the plan duration
                        echo esc_html(sprintf(_n('for %d day', 'for %d days', $plan['duration'], 'subscription-system'), $plan['duration']));
                    } else {
                        esc_html_e('unlimited', 'subscription-system');
                    }
                    ?>
                </div>
            </div>
            
            <ul class="ss-plan-features">
                <?php foreach ($plan['features'] as $feature) : ?>
                    <li><?php echo esc_html($feature); ?></li>
                <?php endforeach; ?>
            </ul>
            
            <button type="button" class="ss-subscribe-btn" data-plan-id="<?php echo esc_attr($plan['id']); ?>">
                <?php esc_html_e('Subscribe Now', 'subscription-system'); ?>
            </button>
        </div>
    <?php endforeach; ?>
</div> 