<?php
/**
 * Upgrade Modal Component
 * Reusable upgrade prompt for free version users
 *
 * @package CommentImageBoost
 * @version 1.0.16
 */

if (!defined('ABSPATH')) {
    die('You are not allowed to call this page directly.');
}

/**
 * Get upgrade modal copy for each locked feature.
 *
 * @return array<string,array<string,mixed>>
 */
function ciboost_get_upgrade_modal_feature_config() {
    return array(
        'compression'     => array(
            'title'       => __('Image Compression & Resize', 'comment-image-boost'),
            'description' => __('Automatically optimize uploaded images to save storage and improve page speed.', 'comment-image-boost'),
            'features'    => array(
                __('Automatic compression for smaller files', 'comment-image-boost'),
                __('Resize large uploads before saving', 'comment-image-boost'),
                __('Progressive image loading support', 'comment-image-boost'),
            ),
        ),
        'multiple-images' => array(
            'title'       => __('Multiple Images per Comment', 'comment-image-boost'),
            'description' => __('Let visitors upload more than one photo with each comment.', 'comment-image-boost'),
            'features'    => array(
                __('Multiple uploads in a single comment', 'comment-image-boost'),
                __('Gallery layouts for attached images', 'comment-image-boost'),
                __('Better photo review and community workflows', 'comment-image-boost'),
            ),
        ),
        'required-images' => array(
            'title'       => __('Required Image Uploads', 'comment-image-boost'),
            'description' => __('Require a photo before a comment can be submitted.', 'comment-image-boost'),
            'features'    => array(
                __('Require images on selected comment forms', 'comment-image-boost'),
                __('Useful for photo reviews and proof submissions', 'comment-image-boost'),
                __('Clear validation messages for visitors', 'comment-image-boost'),
            ),
        ),
        'formats'         => array(
            'title'       => __('Advanced Image Formats', 'comment-image-boost'),
            'description' => __('Accept modern image formats for better quality and smaller uploads.', 'comment-image-boost'),
            'features'    => array(
                __('Enable WebP uploads', 'comment-image-boost'),
                __('Enable AVIF uploads when supported', 'comment-image-boost'),
                __('Control allowed formats from plugin settings', 'comment-image-boost'),
            ),
        ),
        'layouts'         => array(
            'title'       => __('Gallery Layouts', 'comment-image-boost'),
            'description' => __('Display comment images with richer layouts and gallery controls.', 'comment-image-boost'),
            'features'    => array(
                __('Configurable gallery columns', 'comment-image-boost'),
                __('Carousel-style presentation', 'comment-image-boost'),
                __('Responsive layouts for mobile and desktop', 'comment-image-boost'),
            ),
        ),
        'captions'        => array(
            'title'       => __('Image Captions', 'comment-image-boost'),
            'description' => __('Let visitors and moderators add captions to uploaded comment images.', 'comment-image-boost'),
            'features'    => array(
                __('Visitor captions on upload', 'comment-image-boost'),
                __('Moderator caption editing', 'comment-image-boost'),
                __('Cleaner context for photo comments', 'comment-image-boost'),
            ),
        ),
        'filters'         => array(
            'title'       => __('Shortcodes & Integrations', 'comment-image-boost'),
            'description' => __('Create galleries and target where comment image tools are available.', 'comment-image-boost'),
            'features'    => array(
                __('Shortcodes for recent images and galleries', 'comment-image-boost'),
                __('Gutenberg block and Elementor widget', 'comment-image-boost'),
                __('Post type and category targeting', 'comment-image-boost'),
            ),
        ),
    );
}

/**
 * Render the upgrade modal HTML
 * Called on admin pages that have .ciboost-upgrade-trigger buttons
 */
function ciboost_render_upgrade_modal() {
    $upgrade_url = function_exists('ca_fs') && ca_fs() && method_exists(ca_fs(), 'get_upgrade_url')
        ? ca_fs()->get_upgrade_url()
        : '#';
    ?>
    <!-- CIB Upgrade Modal -->
    <div id="ciboost-upgrade-modal" class="ciboost-modal" style="display:none;">
        <div class="ciboost-modal-overlay ciboost-upgrade-overlay"></div>
        <div class="ciboost-modal-container ciboost-upgrade-modal-container">
            <div class="ciboost-modal-header ciboost-upgrade-header">
                <div class="ciboost-upgrade-header-content">
                    <div class="ciboost-upgrade-icon">
                        <span class="dashicons dashicons-star-filled"></span>
                    </div>
                    <h2 class="ciboost-modal-title" id="ciboost-upgrade-title"><?php esc_html_e('Upgrade to Pro', 'comment-image-boost'); ?></h2>
                </div>
                <button class="ciboost-modal-close ciboost-upgrade-close" type="button" aria-label="<?php esc_attr_e('Close', 'comment-image-boost'); ?>">
                    <span class="dashicons dashicons-no-alt"></span>
                </button>
            </div>
            <div class="ciboost-modal-body ciboost-upgrade-body">
                <p class="ciboost-upgrade-description" id="ciboost-upgrade-description"></p>
                <ul class="ciboost-upgrade-features" id="ciboost-upgrade-features"></ul>
                <div class="ciboost-upgrade-cta">
                    <a href="<?php echo esc_url($upgrade_url); ?>" class="ciboost-upgrade-btn-main" target="_blank" rel="noopener">
                        <span class="dashicons dashicons-star-filled"></span>
                        <?php esc_html_e('Upgrade Now', 'comment-image-boost'); ?>
                    </a>
                </div>
            </div>
        </div>
    </div>
    <?php
}
