<?php
/**
 * Index Activity page view
 *
 * @package WebEquipe\PDFSearch
 * @since 1.2.0
 */

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

$webequipe_pdf_manage_url = admin_url( 'admin.php?page=webequipe-pdf-search-manage' );
?>
<div class="wrap webequipe-pdf-activity-wrap" id="webequipe-pdf-activity-page">
	<?php \WebEquipe\PDFSearch\Admin_Settings::render_pro_banner(); ?>

	<div class="webequipe-pdf-activity-header">
		<div class="webequipe-pdf-activity-header-text">
			<h1><?php esc_html_e( 'WebEquipe PDF Search — Index Activity', 'webequipe-pdf-search' ); ?></h1>
			<p class="webequipe-pdf-activity-subtitle">
				<?php esc_html_e( 'Each row is one indexing run. Status for the current run matches Manage PDFs (Processing, Scheduled, Stalled). Older runs keep their final status (Completed, Failed, Cancelled).', 'webequipe-pdf-search' ); ?>
			</p>
		</div>
		<div class="webequipe-pdf-activity-header-actions">
			<a href="<?php echo esc_url( $webequipe_pdf_manage_url ); ?>" class="button button-secondary">
				<?php esc_html_e( 'Manage PDFs', 'webequipe-pdf-search' ); ?>
			</a>
		</div>
	</div>

	<div id="webequipe-pdf-progress" class="webequipe-pdf-activity-progress" style="display: none;">
		<div class="progress-bar">
			<div class="progress-fill"></div>
		</div>
		<p class="progress-text"></p>
	</div>

	<div class="webequipe-pdf-activity-stats" id="webequipe-pdf-activity-stats">
		<div class="webequipe-pdf-activity-stat-card">
			<span class="webequipe-pdf-activity-stat-value" id="activity-stat-total">—</span>
			<span class="webequipe-pdf-activity-stat-label"><?php esc_html_e( 'Total Runs', 'webequipe-pdf-search' ); ?></span>
			<span class="webequipe-pdf-activity-stat-hint"><?php esc_html_e( 'Indexing runs logged', 'webequipe-pdf-search' ); ?></span>
		</div>
		<div class="webequipe-pdf-activity-stat-card">
			<span class="webequipe-pdf-activity-stat-value" id="activity-stat-pages">—</span>
			<span class="webequipe-pdf-activity-stat-label"><?php esc_html_e( 'Total Pages Indexed', 'webequipe-pdf-search' ); ?></span>
			<span class="webequipe-pdf-activity-stat-hint"><?php esc_html_e( 'Pages from completed indexes', 'webequipe-pdf-search' ); ?></span>
		</div>
		<div class="webequipe-pdf-activity-stat-card">
			<span class="webequipe-pdf-activity-stat-value" id="activity-stat-successful">—</span>
			<span class="webequipe-pdf-activity-stat-label"><?php esc_html_e( 'Successful', 'webequipe-pdf-search' ); ?></span>
			<span class="webequipe-pdf-activity-stat-hint"><?php esc_html_e( 'Completed jobs', 'webequipe-pdf-search' ); ?></span>
		</div>
		<div class="webequipe-pdf-activity-stat-card">
			<span class="webequipe-pdf-activity-stat-value" id="activity-stat-processing">—</span>
			<span class="webequipe-pdf-activity-stat-label"><?php esc_html_e( 'In progress', 'webequipe-pdf-search' ); ?></span>
			<span class="webequipe-pdf-activity-stat-hint"><?php esc_html_e( 'Same count as Manage PDFs', 'webequipe-pdf-search' ); ?></span>
		</div>
		<div class="webequipe-pdf-activity-stat-card">
			<span class="webequipe-pdf-activity-stat-value" id="activity-stat-failed">—</span>
			<span class="webequipe-pdf-activity-stat-label"><?php esc_html_e( 'Failed', 'webequipe-pdf-search' ); ?></span>
			<span class="webequipe-pdf-activity-stat-hint"><?php esc_html_e( 'Needs retry', 'webequipe-pdf-search' ); ?></span>
		</div>
	</div>

	<div class="webequipe-pdf-activity-panel">
		<div class="webequipe-pdf-activity-panel-header">
			<div>
				<h2><?php esc_html_e( 'Index Activity', 'webequipe-pdf-search' ); ?></h2>
				<p class="webequipe-pdf-activity-panel-desc">
					<?php esc_html_e( 'Latest indexing runs shown as a serial list. The same document may appear more than once after re-indexing.', 'webequipe-pdf-search' ); ?>
				</p>
			</div>
			<span class="webequipe-pdf-activity-last-updated" id="webequipe-pdf-activity-last-updated"></span>
		</div>

		<div class="webequipe-pdf-activity-toolbar">
			<div class="webequipe-pdf-activity-filters">
				<select id="webequipe-pdf-activity-status-filter" class="webequipe-pdf-activity-select">
					<option value="all"><?php esc_html_e( 'All statuses', 'webequipe-pdf-search' ); ?></option>
					<option value="completed"><?php esc_html_e( 'Completed', 'webequipe-pdf-search' ); ?></option>
					<option value="processing"><?php esc_html_e( 'In progress (Processing / Scheduled / Stalled)', 'webequipe-pdf-search' ); ?></option>
					<option value="scheduled"><?php esc_html_e( 'Scheduled', 'webequipe-pdf-search' ); ?></option>
					<option value="stalled"><?php esc_html_e( 'Stalled', 'webequipe-pdf-search' ); ?></option>
					<option value="failed"><?php esc_html_e( 'Failed', 'webequipe-pdf-search' ); ?></option>
					<option value="cancelled"><?php esc_html_e( 'Cancelled', 'webequipe-pdf-search' ); ?></option>
				</select>
				<select id="webequipe-pdf-activity-per-page" class="webequipe-pdf-activity-select">
					<option value="10">10</option>
					<option value="20" selected>20</option>
					<option value="50">50</option>
				</select>
				<span class="webequipe-pdf-activity-per-page-label"><?php esc_html_e( 'per page', 'webequipe-pdf-search' ); ?></span>
				<input
					type="search"
					id="webequipe-pdf-activity-search"
					class="webequipe-pdf-activity-search"
					placeholder="<?php esc_attr_e( 'Search file name or Media ID...', 'webequipe-pdf-search' ); ?>"
				>
			</div>
			<div class="webequipe-pdf-activity-toolbar-actions">
				<button type="button" id="webequipe-pdf-activity-refresh" class="button button-secondary">
					<span class="dashicons dashicons-update" aria-hidden="true"></span>
					<span><?php esc_html_e( 'Refresh', 'webequipe-pdf-search' ); ?></span>
				</button>
				<button type="button" id="webequipe-pdf-activity-export" class="button button-secondary">
					<?php esc_html_e( 'Export Log', 'webequipe-pdf-search' ); ?>
				</button>
			</div>
		</div>

		<div class="webequipe-pdf-activity-loading" id="webequipe-pdf-activity-loading" style="display: none;">
			<span class="spinner is-active"></span>
			<?php esc_html_e( 'Loading activity...', 'webequipe-pdf-search' ); ?>
		</div>

		<table class="webequipe-pdf-activity-table widefat" id="webequipe-pdf-activity-table">
			<thead>
				<tr>
					<th class="col-sl"><?php esc_html_e( '#', 'webequipe-pdf-search' ); ?></th>
					<th class="col-document"><?php esc_html_e( 'Document Name', 'webequipe-pdf-search' ); ?></th>
					<th class="col-pages"><?php esc_html_e( 'Pages', 'webequipe-pdf-search' ); ?></th>
					<th class="col-status"><?php esc_html_e( 'Status', 'webequipe-pdf-search' ); ?></th>
					<th class="col-updated"><?php esc_html_e( 'Updated', 'webequipe-pdf-search' ); ?></th>
					<th class="col-action"><?php esc_html_e( 'Action', 'webequipe-pdf-search' ); ?></th>
				</tr>
			</thead>
			<tbody id="webequipe-pdf-activity-tbody">
			</tbody>
		</table>

		<div class="webequipe-pdf-activity-footer">
			<p class="webequipe-pdf-activity-summary" id="webequipe-pdf-activity-summary"></p>
			<div class="webequipe-pdf-activity-pagination" id="webequipe-pdf-activity-pagination">
				<button type="button" class="button" id="webequipe-pdf-activity-prev" disabled>
					<?php esc_html_e( 'Previous', 'webequipe-pdf-search' ); ?>
				</button>
				<span class="webequipe-pdf-activity-page-info" id="webequipe-pdf-activity-page-info"></span>
				<button type="button" class="button" id="webequipe-pdf-activity-next" disabled>
					<?php esc_html_e( 'Next', 'webequipe-pdf-search' ); ?>
				</button>
			</div>
		</div>
	</div>
</div>
