<?php
/**
 * Active sessions panel for the settings modal.
 *
 * @var array<string, mixed> $stats
 * @var string               $module_id
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use LoginSessionManager\Includes\Session_Capabilities;
?>
<div class="wpps-lsm-modal-sessions" id="wpps-lsm-modal-sessions">
	<p class="description"><?php esc_html_e( 'Review signed-in devices and revoke sessions you do not recognize.', 'wp-powersuite' ); ?></p>

	<div class="wpps-lsm-stats" id="wpps-lsm-stats">
		<div class="wpps-lsm-stat-card">
			<span class="wpps-lsm-stat-value" data-stat="total_sessions"><?php echo esc_html( (string) ( $stats['total_sessions'] ?? 0 ) ); ?></span>
			<span class="wpps-lsm-stat-label"><?php esc_html_e( 'Active sessions', 'wp-powersuite' ); ?></span>
		</div>
		<div class="wpps-lsm-stat-card">
			<span class="wpps-lsm-stat-value" data-stat="users_logged_in"><?php echo esc_html( (string) ( $stats['users_logged_in'] ?? 0 ) ); ?></span>
			<span class="wpps-lsm-stat-label"><?php esc_html_e( 'Users logged in', 'wp-powersuite' ); ?></span>
		</div>
		<div class="wpps-lsm-stat-card wpps-lsm-stat-card-wide">
			<span class="wpps-lsm-stat-label"><?php esc_html_e( 'Sessions by role', 'wp-powersuite' ); ?></span>
			<div class="wpps-lsm-role-stats" data-stat="sessions_by_role">
				<span class="wpps-lsm-muted"><?php esc_html_e( 'Loading…', 'wp-powersuite' ); ?></span>
			</div>
		</div>
	</div>

	<div class="wpps-lsm-panel">
		<div class="wpps-lsm-toolbar">
			<label class="screen-reader-text" for="wpps-lsm-search"><?php esc_html_e( 'Search sessions', 'wp-powersuite' ); ?></label>
			<input type="search" id="wpps-lsm-search" class="wpps-lsm-search" placeholder="<?php esc_attr_e( 'Search users…', 'wp-powersuite' ); ?>" />
			<div class="wpps-lsm-toolbar-actions">
				<button type="button" class="button" id="wpps-lsm-refresh"><?php esc_html_e( 'Refresh', 'wp-powersuite' ); ?></button>
				<button type="button" class="button" id="wpps-lsm-bulk-logout" disabled><?php esc_html_e( 'Log out selected users', 'wp-powersuite' ); ?></button>
				<?php if ( Session_Capabilities::can_destroy_all_site_wide( get_current_user_id() ) ) : ?>
					<button type="button" class="button button-secondary" id="wpps-lsm-destroy-site"><?php esc_html_e( 'Log out everyone', 'wp-powersuite' ); ?></button>
				<?php endif; ?>
			</div>
		</div>

		<div id="wpps-lsm-loading" class="wpps-lsm-loading" hidden><?php esc_html_e( 'Loading…', 'wp-powersuite' ); ?></div>
		<div id="wpps-lsm-table-wrap" class="wpps-lsm-table-wrap">
			<table class="widefat striped wpps-lsm-table" id="wpps-lsm-table">
				<thead>
					<tr>
						<td class="check-column"><input type="checkbox" id="wpps-lsm-select-all" aria-label="<?php esc_attr_e( 'Select all users', 'wp-powersuite' ); ?>" /></td>
						<th><?php esc_html_e( 'User', 'wp-powersuite' ); ?></th>
						<th><?php esc_html_e( 'Role', 'wp-powersuite' ); ?></th>
						<th><?php esc_html_e( 'IP', 'wp-powersuite' ); ?></th>
						<th><?php esc_html_e( 'Device', 'wp-powersuite' ); ?></th>
						<th><?php esc_html_e( 'Login', 'wp-powersuite' ); ?></th>
						<th><?php esc_html_e( 'Expires', 'wp-powersuite' ); ?></th>
						<th><?php esc_html_e( 'Actions', 'wp-powersuite' ); ?></th>
					</tr>
				</thead>
				<tbody id="wpps-lsm-table-body">
					<tr><td colspan="8"><?php esc_html_e( 'Loading sessions…', 'wp-powersuite' ); ?></td></tr>
				</tbody>
			</table>
		</div>

		<div class="wpps-lsm-pagination" id="wpps-lsm-pagination" hidden>
			<button type="button" class="button" id="wpps-lsm-prev-page" disabled><?php esc_html_e( 'Previous', 'wp-powersuite' ); ?></button>
			<span class="wpps-lsm-page-info" id="wpps-lsm-page-info" aria-live="polite"></span>
			<button type="button" class="button" id="wpps-lsm-next-page" disabled><?php esc_html_e( 'Next', 'wp-powersuite' ); ?></button>
		</div>
	</div>
</div>
