<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

if ( empty( $user->ID ) ) {
	return;
}

if ( ! current_user_can( 'edit_user', $user->ID ) ) {
	return;
}

if ( ! gigneo_user_have_access( $user->ID ) ) {
	return;
}

// Get current value
$gigneo_active_profile     = get_user_meta( $user->ID, '_gigneo_um_active_profile', true );
$gigneo_freelancer_profile = get_user_meta( $user->ID, '_gigneo_um_freelancer_profile_id', true );
$gigneo_employer_profile   = get_user_meta( $user->ID, '_gigneo_um_employer_profile_id', true );

if ( empty( $gigneo_freelancer_profile ) && empty( $gigneo_employer_profile ) ) {
	return;
}

?>
<h2><?php echo esc_html__( 'Gigneo - Switch role', 'gigneo' ); ?></h2>
<?php wp_nonce_field( 'gigneo_switch_role', 'gigneo_switch_role_nonce' ); ?>
<table class="form-table">
	<tr>
		<th><label for="gigneo_active_profile"><?php echo esc_html__( 'Active profile', 'gigneo' ); ?></label></th>
		<td>
			<select name="gigneo_active_profile" id="gigneo_active_profile">
				<?php if ( ! empty( $gigneo_freelancer_profile ) ) { ?>
					<option value="freelancer" <?php selected( $gigneo_active_profile, 'freelancer' ); ?>><?php echo esc_html( gigneo_freelancer_singular() ); ?></option>
					<?php
				}
				if ( ! empty( $gigneo_employer_profile ) ) {
					?>
					<option value="employer" <?php selected( $gigneo_active_profile, 'employer' ); ?>><?php echo esc_html( gigneo_employer_singular() ); ?></option>
				<?php } ?>
			</select>
		</td>
	</tr>
</table>