<?php
/**
 * Bulk optimization template.
 *
 * @package NaveenCodesImageOptimizer
 */

defined( 'ABSPATH' ) || exit;

(
	static function ( $banner, $health, $queue_counts, $settings, $stats, $queue_sections_html, $bulk_session ) {
		$ultra_image_optimizer_total    = max( 1, (int) $queue_counts['total'] );
		$ultra_image_optimizer_done     = (int) $queue_counts['completed'] + (int) $queue_counts['failed'];
		$ultra_image_optimizer_progress = round( ( $ultra_image_optimizer_done / $ultra_image_optimizer_total ) * 100, 2 );
		?>
<div class="wrap naveencodes-wrap">
	<?php include NAVEENCODES_DIR . 'templates/admin-banner.php'; ?>
	<div class="naveencodes-header">
		<div>
			<h1><?php esc_html_e( 'Optimize Media', 'naveencodes-image-optimizer' ); ?></h1>
			<p class="naveencodes-subtitle"><?php esc_html_e( 'Queue your Media Library, watch progress live, and review each optimized image with clear before and after size data.', 'naveencodes-image-optimizer' ); ?></p>
		</div>
		<div class="naveencodes-header-actions">
			<span class="naveencodes-badge <?php echo esc_attr( $health['badge_class'] ); ?>">
				<?php esc_html_e( 'Health', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( $health['label'] ); ?>
			</span>
			<a class="button button-secondary" href="<?php echo esc_url( admin_url( 'upload.php' ) ); ?>">
				<?php esc_html_e( 'Media Library', 'naveencodes-image-optimizer' ); ?>
			</a>
		</div>
	</div>

	<div class="naveencodes-panel naveencodes-panel--hero" data-naveencodes-live-progress>
		<div class="naveencodes-panel-head">
			<div>
				<h2><?php esc_html_e( 'Bulk Optimization Progress', 'naveencodes-image-optimizer' ); ?></h2>
				<p class="naveencodes-help"><?php esc_html_e( 'The queue can be started again anytime. Already optimized items remain tracked, and unfinished items continue from where they stopped.', 'naveencodes-image-optimizer' ); ?></p>
			</div>
			<div class="naveencodes-actions">
				<button type="button" class="button button-primary" data-naveencodes-run-bulk>
					<?php esc_html_e( 'Start Bulk Optimization', 'naveencodes-image-optimizer' ); ?>
				</button>
				<a class="button button-secondary" href="<?php echo esc_url( admin_url( 'admin.php?page=naveencodes-settings' ) ); ?>">
					<?php esc_html_e( 'Review Compression Profile', 'naveencodes-image-optimizer' ); ?>
				</a>
			</div>
		</div>

		<div class="naveencodes-progress" aria-label="<?php esc_attr_e( 'Bulk optimization progress', 'naveencodes-image-optimizer' ); ?>">
			<div class="naveencodes-progress-bar" data-naveencodes-progress-bar style="width: <?php echo esc_attr( $ultra_image_optimizer_progress ); ?>%;"></div>
		</div>
		<div class="naveencodes-progress-meta">
			<strong data-naveencodes-progress-percent><?php echo esc_html( number_format_i18n( $ultra_image_optimizer_progress, 2 ) ); ?>%</strong>
			<span data-naveencodes-progress-counts>
				<?php esc_html_e( 'Pending', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( number_format_i18n( (int) $queue_counts['pending'] ) ); ?>
				|
				<?php esc_html_e( 'Processing', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( number_format_i18n( (int) $queue_counts['processing'] ) ); ?>
				|
				<?php esc_html_e( 'Completed', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( number_format_i18n( (int) $queue_counts['completed'] ) ); ?>
				|
				<?php esc_html_e( 'Failed', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( number_format_i18n( (int) $queue_counts['failed'] ) ); ?>
			</span>
		</div>

		<p class="naveencodes-session-info" data-naveencodes-session-info hidden></p>
		<p class="naveencodes-help" data-naveencodes-status><?php esc_html_e( 'Ready to scan your media library.', 'naveencodes-image-optimizer' ); ?></p>

		<ul class="naveencodes-status-list" data-naveencodes-status-tabs>
			<li><button type="button" class="naveencodes-badge naveencodes-badge--info is-active" data-naveencodes-status-tab="pending" data-naveencodes-count-pending><?php esc_html_e( 'Pending', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( number_format_i18n( (int) $queue_counts['pending'] ) ); ?></button></li>
			<li><button type="button" class="naveencodes-badge naveencodes-badge--warning" data-naveencodes-status-tab="processing" data-naveencodes-count-processing><?php esc_html_e( 'Processing', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( number_format_i18n( (int) $queue_counts['processing'] ) ); ?></button></li>
			<li><button type="button" class="naveencodes-badge naveencodes-badge--success" data-naveencodes-status-tab="completed" data-naveencodes-count-completed><?php esc_html_e( 'Completed', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( number_format_i18n( (int) $queue_counts['completed'] ) ); ?></button></li>
			<li><button type="button" class="naveencodes-badge naveencodes-badge--danger" data-naveencodes-status-tab="failed" data-naveencodes-count-failed><?php esc_html_e( 'Failed', 'naveencodes-image-optimizer' ); ?>: <?php echo esc_html( number_format_i18n( (int) $queue_counts['failed'] ) ); ?></button></li>
		</ul>
	</div>

	<div class="naveencodes-grid naveencodes-grid--queue-status" data-naveencodes-status-panels>
		<div class="naveencodes-panel naveencodes-panel--status is-active" id="naveencodes-status-pending" data-naveencodes-status-panel="pending">
			<div class="naveencodes-panel-head naveencodes-panel-head--compact">
				<div>
					<h2><?php esc_html_e( 'Pending Images', 'naveencodes-image-optimizer' ); ?></h2>
					<p class="naveencodes-help"><?php esc_html_e( 'Queued images waiting to start.', 'naveencodes-image-optimizer' ); ?></p>
				</div>
				<span class="naveencodes-badge naveencodes-badge--info" data-naveencodes-status-panel-count="pending"><?php echo esc_html( number_format_i18n( (int) $queue_counts['pending'] ) ); ?></span>
			</div>
			<div data-naveencodes-queue-section="pending"><?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe internal admin markup. echo $queue_sections_html['pending'] ?? ''; ?></div>
		</div>

		<div class="naveencodes-panel naveencodes-panel--status" id="naveencodes-status-processing" data-naveencodes-status-panel="processing" hidden>
			<div class="naveencodes-panel-head naveencodes-panel-head--compact">
				<div>
					<h2><?php esc_html_e( 'Processing Images', 'naveencodes-image-optimizer' ); ?></h2>
					<p class="naveencodes-help"><?php esc_html_e( 'Images currently being optimized.', 'naveencodes-image-optimizer' ); ?></p>
				</div>
				<span class="naveencodes-badge naveencodes-badge--warning" data-naveencodes-status-panel-count="processing"><?php echo esc_html( number_format_i18n( (int) $queue_counts['processing'] ) ); ?></span>
			</div>
			<div data-naveencodes-queue-section="processing"><?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe internal admin markup. echo $queue_sections_html['processing'] ?? ''; ?></div>
		</div>

		<div class="naveencodes-panel naveencodes-panel--status" id="naveencodes-status-completed" data-naveencodes-status-panel="completed" hidden>
			<div class="naveencodes-panel-head naveencodes-panel-head--compact">
				<div>
					<h2><?php esc_html_e( 'Completed Images', 'naveencodes-image-optimizer' ); ?></h2>
					<p class="naveencodes-help"><?php esc_html_e( 'Recently completed media items from the queue.', 'naveencodes-image-optimizer' ); ?></p>
				</div>
				<span class="naveencodes-badge naveencodes-badge--success" data-naveencodes-status-panel-count="completed"><?php echo esc_html( number_format_i18n( (int) $queue_counts['completed'] ) ); ?></span>
			</div>
			<div data-naveencodes-queue-section="completed"><?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe internal admin markup. echo $queue_sections_html['completed'] ?? ''; ?></div>
		</div>

		<div class="naveencodes-panel naveencodes-panel--status" id="naveencodes-status-failed" data-naveencodes-status-panel="failed" hidden>
			<div class="naveencodes-panel-head naveencodes-panel-head--compact">
				<div>
					<h2><?php esc_html_e( 'Failed Images', 'naveencodes-image-optimizer' ); ?></h2>
					<p class="naveencodes-help"><?php esc_html_e( 'Images that need review before another attempt.', 'naveencodes-image-optimizer' ); ?></p>
				</div>
				<span class="naveencodes-badge naveencodes-badge--danger" data-naveencodes-status-panel-count="failed"><?php echo esc_html( number_format_i18n( (int) $queue_counts['failed'] ) ); ?></span>
			</div>
			<div data-naveencodes-queue-section="failed"><?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe internal admin markup. echo $queue_sections_html['failed'] ?? ''; ?></div>
		</div>
	</div>

	<div class="naveencodes-grid naveencodes-grid--stats">
		<div class="naveencodes-card">
			<p class="naveencodes-card-label"><?php esc_html_e( 'Images Per Batch', 'naveencodes-image-optimizer' ); ?></p>
			<p class="naveencodes-card-value"><?php echo esc_html( number_format_i18n( (int) $settings['batch_size'] ) ); ?></p>
			<p class="naveencodes-card-note"><?php esc_html_e( 'Adjust this in Batch Settings for slower or faster hosting.', 'naveencodes-image-optimizer' ); ?></p>
		</div>
		<div class="naveencodes-card">
			<p class="naveencodes-card-label"><?php esc_html_e( 'Optimized Attachments', 'naveencodes-image-optimizer' ); ?></p>
			<p class="naveencodes-card-value" data-naveencodes-stat="total_optimized"><?php echo esc_html( number_format_i18n( (int) $stats['total_optimized'] ) ); ?></p>
			<p class="naveencodes-card-note"><?php esc_html_e( 'Successful media items so far.', 'naveencodes-image-optimizer' ); ?></p>
		</div>
		<div class="naveencodes-card">
			<p class="naveencodes-card-label"><?php esc_html_e( 'Space Saved', 'naveencodes-image-optimizer' ); ?></p>
			<p class="naveencodes-card-value" data-naveencodes-stat-format="bytes" data-naveencodes-stat="total_saved_bytes"><?php echo esc_html( size_format( (int) $stats['total_saved_bytes'], 2 ) ); ?></p>
			<p class="naveencodes-card-note"><?php esc_html_e( 'Visible savings across all successful runs.', 'naveencodes-image-optimizer' ); ?></p>
		</div>
		<div class="naveencodes-card">
			<p class="naveencodes-card-label"><?php esc_html_e( 'Average Compression', 'naveencodes-image-optimizer' ); ?></p>
			<p class="naveencodes-card-value" data-naveencodes-stat-format="percent" data-naveencodes-stat="average_compression"><?php echo esc_html( number_format_i18n( (float) $stats['average_compression'], 2 ) ); ?>%</p>
			<p class="naveencodes-card-note"><?php esc_html_e( 'Average size reduction compared with original files.', 'naveencodes-image-optimizer' ); ?></p>
		</div>
	</div>

</div>
		<?php
	}
)( $banner, $health, $queue_counts, $settings, $stats, $queue_sections_html, $bulk_session );
