<?php
/**
 * Template to display a User Registration Form.
 *
 * @package voidempo
 */

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

if ( ! is_user_logged_in() ) {
	wp_safe_redirect( wp_login_url() );
	exit;
}

?>

<body>
<div class="mt-5">
  <div class="container">
    <h2>User Registration</h2>
    <form class="registration-form" id="registration-form">
      <div class="row g-3 p-3" style="box-shadow: 0 1px 12px rgb(0 0 0 / 29%); background-color: #F3F3F3; border-radius: 8px; margin-top: 15px; margin-bottom: 15px;">

        <!-- Normal fields -->
        <div class="col-md-3">
          <label for="username" class="form-label">Username *</label>
          <input type="text" class="form-control" name="username" id="username" required placeholder="Enter username">
          <p class="error" id="error_username"></p>
        </div>

        <div class="col-md-3">
          <label for="email" class="form-label">Email *</label>
          <input type="email" class="form-control" name="email" id="email" required placeholder="Enter email">
          <p class="error" id="error_email"></p>
        </div>

        <div class="col-md-3">
          <label for="password" class="form-label">Password *</label>
          <input type="password" class="form-control" name="password" id="password" required placeholder="Enter password">
          <p class="error" id="error_password"></p>
        </div>

        <div class="col-md-3">
          <label for="first_name" class="form-label">First Name</label>
          <input type="text" class="form-control" name="first_name" id="first_name" placeholder="First name">
          <p class="error" id="error_first_name"></p>
        </div>

        <div class="col-md-3">
          <label for="last_name" class="form-label">Last Name</label>
          <input type="text" class="form-control" name="last_name" id="last_name" placeholder="Last name">
          <p class="error" id="error_last_name"></p>
        </div>

        <div class="col-md-3">
          <label for="user_dob" class="form-label">Date of Birth</label>
          <input type="date" class="form-control" name="user_dob" id="user_dob" max="<?php echo esc_attr( gmdate( 'Y-m-d' ) ); ?>">
        </div>

        <div class="col-md-3">
          <label for="user_joining_date" class="form-label">Date of Joining</label>
          <input type="date" class="form-control" name="user_joining_date" id="user_joining_date">
        </div>
        <?php do_action( 'voidempo_registration_form_extra_fields' ); ?>
      </div>

      <div class="text-center mt-4">
        <button type="submit" name="submit_user" id="btn_user" class="btn btn-primary">Register User</button>
      </div>
    </form>
  </div>
</div>

<table class="table table-bordered" id="userTable">
	<thead>
		<tr>
			<th>Name</th>
			<th>Email</th>
			<th>DOB</th>
			<th>Joining Date</th>
			<?php
				do_action( 'voidempo_user_table_extra_columns' );
			?>
			<th>Actions</th>
		</tr>
	</thead>
</table>

<div class="modal fade" id="editUserModal" tabindex="-1" aria-hidden="true" role="dialog" aria-labelledby="editUserLabel">
	<div class="modal-dialog  modal-lg" role="document">
	<div class="modal-content">
		<form id="editUserForm">
		<div class="modal-header">
			<h5 class="modal-title">Edit User</h5>
			<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
		</div>
		<div class="modal-body row">
			<input type="hidden" name="user_id" id="edit_user_id">

			<div class="form-group col-md-3">
			<label>Name</label>
				<input type="text" class="form-control" name="name" id="edit_user_name" >
			</div>
			<div class="form-group col-md-3">
			<label>DOB</label>
				<input type="date" class="form-control" name="dob" id="edit_user_dob">
			</div>
			<div class="form-group col-md-3">
			<label>Joining Date</label>
				<input type="date" class="form-control" name="joining" id="edit_user_joining">
			</div>
		
			<div class="form-group col-md-3">
				<label>Status</label>
				<div style="display:flex;">
					<div class="form-check mt-1" style="display:inline-flex; padding-left: 0.5em !important;">
						<input  type="radio" name="employee_status" id="status_active" value="active">
						<label  for="status_active" style="margin-left: 5px;">Active</label>
					</div>
					<div class="form-check mt-1" style="display:inline-flex; padding-left: 0.5em !important;">
						<input  type="radio" name="employee_status" id="status_deactive" value="deactive">
						<label  for="status_deactive" style="margin-left: 5px;">Deactive</label>
					</div>
				</div>
			</div>

			<?php
			do_action( 'voidempo_render_leave_config_form' );
			?>
		</div>
		<div class="modal-footer">
			<button type="submit" class="btn btn-success update_user_btn" id="update_user_btn">Update</button>
			<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
		</div>
		</form>
	</div>
	</div>
</div>
<?php
require VOIDEMPO_PLUGIN_PATH . 'templates/footer.php';
?>
