<?php
/**
 * Image Boost — Bulk Optimize View
 */

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

$imgboost_stats = ImgBoost_Stats::get_dashboard_stats();
$imgboost_level = get_option('imgboost_compression_level', 'pro');
?>

<div class="imgboost-wrap">
    <!-- Header -->
    <div class="imgboost-header">
        <div class="imgboost-header-content">
            <div class="imgboost-header-left">
                <div class="imgboost-logo">
                    <span class="dashicons dashicons-images-alt2"></span>
                </div>
                <div>
                    <h1><?php esc_html_e('Bulk Optimize', 'image-boost'); ?></h1>
                    <p class="imgboost-subtitle"><?php esc_html_e('Optimize your entire media library in one go', 'image-boost'); ?></p>
                </div>
            </div>
        </div>
    </div>

    <!-- Bulk Controls -->
    <div class="imgboost-bulk-controls">
        <div class="imgboost-bulk-summary">
            <div class="imgboost-bulk-stat">
                <span class="imgboost-bulk-stat-number" id="bulk-total"><?php echo esc_html($imgboost_stats['total_images']); ?></span>
                <span class="imgboost-bulk-stat-label"><?php esc_html_e('Total Images', 'image-boost'); ?></span>
            </div>
            <div class="imgboost-bulk-stat">
                <span class="imgboost-bulk-stat-number imgboost-text-success" id="bulk-optimized"><?php echo esc_html($imgboost_stats['optimized_count']); ?></span>
                <span class="imgboost-bulk-stat-label"><?php esc_html_e('Already Optimized', 'image-boost'); ?></span>
            </div>
            <div class="imgboost-bulk-stat">
                <span class="imgboost-bulk-stat-number imgboost-text-warning" id="bulk-pending"><?php echo esc_html($imgboost_stats['pending_count']); ?></span>
                <span class="imgboost-bulk-stat-label"><?php esc_html_e('Pending', 'image-boost'); ?></span>
            </div>
        </div>

        <?php if ($imgboost_stats['pending_count'] == 0): ?>
            <div class="imgboost-all-done" style="flex-direction: column; text-align: center; justify-content: center; padding: 40px; margin-top: 10px;">
                <span style="font-size: 48px; display: block; margin-bottom: 16px;">🎉</span>
                <h2 style="color: #6ee7b7; font-size: 24px; margin: 0 0 10px; font-weight: 700;"><?php esc_html_e('All Images Are Optimized!', 'image-boost'); ?></h2>
                <p style="color: #a7f3d0; font-size: 16px; margin: 0;">
                    <?php 
                    /* translators: 1: number of images optimized, 2: total size saved */
                    printf(esc_html__('You have compressed %1$d images saving %2$s of space.', 'image-boost'), (int) $imgboost_stats['optimized_count'], esc_html($imgboost_stats['total_saved_human'])); 
                    ?>
                </p>
            </div>
        <?php else: ?>
            <div class="imgboost-bulk-actions" style="justify-content: center;">
                <div class="imgboost-bulk-buttons">
                    <button type="button" id="imgboost-start-bulk" class="imgboost-btn imgboost-btn-primary" style="padding: 16px 32px; font-size: 16px;">
                        ⚡ <?php esc_html_e('Start Bulk Optimization', 'image-boost'); ?>
                    </button>
                    <button type="button" id="imgboost-pause-bulk" class="imgboost-btn imgboost-btn-secondary" style="display:none; padding: 16px 32px; font-size: 16px;">
                        ⏸ <?php esc_html_e('Pause', 'image-boost'); ?>
                    </button>
                    <button type="button" id="imgboost-resume-bulk" class="imgboost-btn imgboost-btn-success" style="display:none; padding: 16px 32px; font-size: 16px;">
                        ▶ <?php esc_html_e('Resume', 'image-boost'); ?>
                    </button>
                </div>
            </div>
        <?php endif; ?>
    </div>

    <!-- Progress Bar -->
    <div class="imgboost-bulk-progress" id="bulk-progress-section" style="display:none;">
        <div class="imgboost-progress-header">
            <span id="bulk-progress-status"><?php esc_html_e('Optimizing...', 'image-boost'); ?></span>
            <span id="bulk-progress-pct">0%</span>
        </div>
        <div class="imgboost-progress-bar-container">
            <div class="imgboost-progress-bar" id="bulk-progress-bar" style="width:0%">
                <div class="imgboost-progress-bar-glow"></div>
            </div>
        </div>
        <div class="imgboost-progress-details">
            <span id="bulk-progress-count">0 / 0</span>
            <span id="bulk-progress-speed"></span>
        </div>
    </div>

    <!-- Results Log -->
    <div class="imgboost-bulk-results" id="bulk-results-section" style="display:none;">
        <h3><?php esc_html_e('Results', 'image-boost'); ?></h3>
        <div class="imgboost-results-table-wrap">
            <table class="imgboost-results-table">
                <thead>
                    <tr>
                        <th><?php esc_html_e('Image', 'image-boost'); ?></th>
                        <th><?php esc_html_e('File', 'image-boost'); ?></th>
                        <th><?php esc_html_e('Original', 'image-boost'); ?></th>
                        <th><?php esc_html_e('Optimized', 'image-boost'); ?></th>
                        <th><?php esc_html_e('Savings', 'image-boost'); ?></th>
                        <th><?php esc_html_e('Level', 'image-boost'); ?></th>
                        <th><?php esc_html_e('Status', 'image-boost'); ?></th>
                    </tr>
                </thead>
                <tbody id="bulk-results-body">
                </tbody>
            </table>
        </div>
    </div>
</div>
