<?php
/**
 * User management tab: lists users and lets an admin manage their roles.
 *
 * @package wpss-ultimate-user-management
 */

/** Prevent direct access */
if ( ! defined( 'ABSPATH' ) ) {
	header( 'HTTP/1.0 403 Forbidden' );
	exit;
}

use WpssUserManager\Admin\WPSSAdminFrontend;
use WpssUserManager\Admin\WPSSPluginHelper;
use WpssUserManager\Admin\RoleCraftRequest;
use WpssUserManager\Admin\WPSSUsers;
use WpssUserManager\Admin\WPSSUserRolesCapsManager;

$wpss_nonce = wp_create_nonce( WPSSUserRolesCapsManager::nonce() );
?>
<p>
	<?php esc_html_e( 'Select the user to add or remove access permissions. A user can own one or more permissions.', 'wpss-ultimate-user-management' ); ?>
</p>
<hr>
<?php
$wpss_search = RoleCraftRequest::get( 'wpss-user-search', $wpss_nonce );
?>
<form method="get" action="<?php echo esc_url( admin_url() ); ?>" class="wpss-user-select">
	<input type="hidden" name="page" value="wpss-ultimate-user-management-admin-menu">
	<input type="hidden" name="tab" value="users-tab">
	<label for="wpss-user-search">
		<strong><?php esc_html_e( 'Search User', 'wpss-ultimate-user-management' ); ?>:</strong>
		<input type="search" value="<?php echo esc_attr( $wpss_search ); ?>" name="wpss-user-search" id="wpss-user-search" required="required">
		
		<button type="submit" class="button-primary">
			<?php esc_html_e( 'Search', 'wpss-ultimate-user-management' ); ?>
		</button>
	</label>
	<?php
	$wpss_template = [
		'template' => 'content/users-table',
		'args'     => WPSSUsers::get_users( WPSSPluginHelper::get_option( 'wpss_user_entries_screen' ), $wpss_search ),
	];
	WPSSAdminFrontend::render( $wpss_template );
	?>
</form><!-- .wpss-user-select -->

<div class="role-editor-messages d-none">
</div><!-- .role-editor-messages -->

<div id="user-details-container" class="user-details-container d-none">
	<hr>
	<div></div>
</div><!-- .user-details-container -->
