<?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.', 'wppowersuite-lite' ); ?></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', 'wppowersuite-lite' ); ?></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', 'wppowersuite-lite' ); ?></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', 'wppowersuite-lite' ); ?></span>
			<div class="wpps-lsm-role-stats" data-stat="sessions_by_role">
				<span class="wpps-lsm-muted"><?php esc_html_e( 'Loading…', 'wppowersuite-lite' ); ?></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', 'wppowersuite-lite' ); ?></label>
			<input type="search" id="wpps-lsm-search" class="wpps-lsm-search" placeholder="<?php esc_attr_e( 'Search users…', 'wppowersuite-lite' ); ?>" />
			<div class="wpps-lsm-toolbar-actions">
				<button type="button" class="button" id="wpps-lsm-refresh"><?php esc_html_e( 'Refresh', 'wppowersuite-lite' ); ?></button>
				<button type="button" class="button" id="wpps-lsm-bulk-logout" disabled><?php esc_html_e( 'Log out selected users', 'wppowersuite-lite' ); ?></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', 'wppowersuite-lite' ); ?></button>
				<?php endif; ?>
			</div>
		</div>

		<div id="wpps-lsm-loading" class="wpps-lsm-loading" hidden><?php esc_html_e( 'Loading…', 'wppowersuite-lite' ); ?></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', 'wppowersuite-lite' ); ?>" /></td>
						<th><?php esc_html_e( 'User', 'wppowersuite-lite' ); ?></th>
						<th><?php esc_html_e( 'Role', 'wppowersuite-lite' ); ?></th>
						<th><?php esc_html_e( 'IP', 'wppowersuite-lite' ); ?></th>
						<th><?php esc_html_e( 'Device', 'wppowersuite-lite' ); ?></th>
						<th><?php esc_html_e( 'Login', 'wppowersuite-lite' ); ?></th>
						<th><?php esc_html_e( 'Expires', 'wppowersuite-lite' ); ?></th>
						<th><?php esc_html_e( 'Actions', 'wppowersuite-lite' ); ?></th>
					</tr>
				</thead>
				<tbody id="wpps-lsm-table-body">
					<tr><td colspan="8"><?php esc_html_e( 'Loading sessions…', 'wppowersuite-lite' ); ?></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', 'wppowersuite-lite' ); ?></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', 'wppowersuite-lite' ); ?></button>
		</div>
	</div>
</div>
