<?php
/**
 * AI Alt Text review queue tab.
 *
 * @package AIAltTextGenerator
 */

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

use AIAltTextGenerator\AdminActions;
use AIAltTextGenerator\Capabilities;
use AIAltTextGenerator\ReviewListTable;

require_once __DIR__ . '/helpers.php';

if ( ! Capabilities::canGenerate() ) {
	echo '<div class="wpps-ai-alt-notice wpps-ai-alt-notice--warning"><p>' . esc_html__( 'You do not have permission to review suggestions.', 'wp-powersuite' ) . '</p></div>';
	return;
}

if ( isset( $_GET['bulk_done'], $_GET['bulk_count'] ) ) {
	$action = sanitize_key( wp_unslash( (string) $_GET['bulk_done'] ) );
	$count  = max( 0, (int) $_GET['bulk_count'] );
	if ( $count > 0 ) {
		printf(
			'<div class="notice notice-success is-dismissible"><p>%s</p></div>',
			esc_html(
				sprintf(
					/* translators: 1: number of images, 2: bulk action key */
					__( 'Bulk action complete: %1$d item(s) processed (%2$s).', 'wp-powersuite' ),
					$count,
					$action
				)
			)
		);
	}
}

$list_table = new ReviewListTable();
$list_table->prepare_items();
?>
<div class="wpps-ai-alt-review-page">
	<div class="wpps-ai-alt-card">
		<div class="wpps-ai-alt-card-head">
			<h2 class="wpps-ai-alt-card-title"><?php esc_html_e( 'Review suggestions', 'wp-powersuite' ); ?></h2>
			<p class="wpps-ai-alt-card-desc"><?php esc_html_e( 'Approve, edit, reject, or regenerate AI suggestions before they are saved to the media library.', 'wp-powersuite' ); ?></p>
		</div>
		<div class="wpps-ai-alt-card-body">
			<form method="post">
				<?php
				wp_nonce_field( AdminActions::NONCE_ACTION, AdminActions::NONCE_ACTION );
				$list_table->search_box( __( 'Search review queue', 'wp-powersuite' ), 'wpps-ai-alt-review' );
				$list_table->display();
				?>
			</form>
		</div>
	</div>
</div>
