<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Prevent direct access to the script.
}

$profile_id         = $args['profile_id'] ?? gigneo_active_profile_id();
$author_id          = get_post_field( 'post_author', $profile_id );
$current_login_user = get_userdata( $author_id );
$author_email       = get_the_author_meta( 'user_email', $author_id );
$author_id          = gigneo_format_id( $author_id, 'user', false );
$full_name          = gigneo_profile_name( $profile_id );
?>
<div id="gn-account-user-info" class="gn-dashboard-section gn-account-user-info">
	<div class="gn-head">
		<div class="gn-heading-info">
			<h3 class="gn-title"><?php echo esc_html__( 'User information', 'gigneo' ); ?></h3>
			<p class="gn-description"><?php echo esc_html__( 'Manage or update your information and details.', 'gigneo' ); ?></p>
		</div>
		<button class="gn-link gn-link-primary" data-gn-modal-toggle="gn-edit-user-account-info">
			<i class="hi hi-pencil-edit" aria-hidden="true"></i>
			<?php echo esc_html__( 'Edit', 'gigneo' ); ?>
		</button>
	</div>
	<div class="gn-body">
		<div class="gn-stat-cards">
			<div class="gn-stat-card">
				<h3 class="gn-label">
					<i class="hi hi-hashtag" aria-hidden="true"></i>
					<?php echo esc_html__( 'User ID', 'gigneo' ); ?>
				</h3>
				<h5 class="gn-value"><?php echo esc_html( $author_id ); ?></h5>
			</div>
			<div class="gn-stat-card">
				<h3 class="gn-label">
					<i class="hi hi-user" aria-hidden="true"></i>
					<?php echo esc_html__( 'Full name', 'gigneo' ); ?>
				</h3>
				<h5 class="gn-value"><?php echo esc_html( $full_name ); ?></h5>
			</div>
			<div class="gn-stat-card">
				<h3 class="gn-label">
					<i class="hi hi-envelope" aria-hidden="true"></i>
					<?php echo esc_html__( 'Email address', 'gigneo' ); ?>
				</h3>
				<h5 class="gn-value"><?php echo esc_html( $author_email ); ?></h5>
			</div>
		</div>
	</div>
	<!--Edit User Info Modal-->
	<div id="gn-edit-user-account-info" class="gn-modal-wrapper gn-user-setting-modal">
		<div class="gn-modal-dialog">
			<div class="gn-modal-content">
				<div class="gn-modal-info">
					<div class="gn-modal-header">
						<h4 class="gn-title"><?php echo esc_html__( 'User Information', 'gigneo' ); ?></h4>
						<p class="gn-description"><?php echo esc_html__( 'Manage or update your information.', 'gigneo' ); ?></p>
						<button type="button" data-gn-modal-close="gn-edit-user-account-info" class="gn-modal-close">
							<i class="hi hi-x-mark" aria-hidden="true"></i>
						</button>
					</div>
					<form id="gn-save-account-setting-form" class="gn-theme-form gn-save-user-account-setting">
						<div class="gn-modal-body gn-custom-scrollbar">
							<fieldset class="gn-form-fields">
								<div class="row g-4">
									<div class="col-md-6">
										<div class="gn-form-field">
											<label class="gn-required-field-label" for="gn-first-name"><?php echo esc_html__( 'First Name', 'gigneo' ); ?></label>
											<input id="gn-first-name" class="gn-required-field" type="text" name="first_name" autocomplete="off" value="<?php echo esc_attr( $current_login_user->first_name ); ?>" placeholder="<?php echo esc_attr__( 'Enter first name', 'gigneo' ); ?>">
										</div>
									</div>
									<div class="col-md-6">
										<div class="gn-form-field">
											<label class="gn-required-field-label" for="gn-last-name"><?php echo esc_html__( 'Last Name', 'gigneo' ); ?></label>
											<input id="gn-last-name" class="gn-required-field" type="text" name="last_name" autocomplete="off" value="<?php echo esc_attr( $current_login_user->last_name ); ?>" placeholder="<?php echo esc_attr__( 'Enter last name', 'gigneo' ); ?>">
										</div>
									</div>
									<div class="col-md-6">
										<div class="gn-form-field">
											<label class="gn-required-field-label" for="gn-nickname"><?php echo esc_html__( 'Nickname', 'gigneo' ); ?></label>
											<input id="gn-nickname" class="gn-required-field" type="text" name="nickname" autocomplete="off" value="<?php echo esc_attr( $current_login_user->nickname ); ?>" placeholder="<?php echo esc_attr__( 'Enter nickname', 'gigneo' ); ?>">
										</div>
									</div>
									<div class="col-md-6">
										<div class="gn-form-field gn-select2">
											<label for="gn-display-name"><?php echo esc_html__( 'Display name', 'gigneo' ); ?></label>
											<select id="gn-display-name" name="display_name" data-minimum-results-for-search="Infinity">
												<?php
												$public_display                     = array();
												$public_display['display_nickname'] = $current_login_user->nickname;
												$public_display['display_username'] = $current_login_user->user_login;

												if ( ! empty( $current_login_user->first_name ) ) {
													$public_display['display_firstname'] = $current_login_user->first_name;
												}

												if ( ! empty( $current_login_user->last_name ) ) {
													$public_display['display_lastname'] = $current_login_user->last_name;
												}

												if ( ! empty( $current_login_user->first_name ) && ! empty( $current_login_user->last_name ) ) {
													$public_display['display_firstlast'] = $current_login_user->first_name . ' ' . $current_login_user->last_name;
													$public_display['display_lastfirst'] = $current_login_user->last_name . ' ' . $current_login_user->first_name;
												}

												if ( ! in_array( $current_login_user->display_name, $public_display, true ) ) { // Only add this if it isn't duplicated elsewhere.
													$public_display = array( 'display_displayname' => $current_login_user->display_name ) + $public_display;
												}

												$public_display = array_map( 'trim', $public_display );
												$public_display = array_unique( $public_display );

												?>
												<?php foreach ( $public_display as $uid => $item ) : ?>
													<option <?php selected( $current_login_user->display_name, $item ); ?>><?php echo esc_html( $item ); ?></option>
												<?php endforeach; ?>
											</select>
										</div>
									</div>
									<div class="col-md-12">
										<div class="gn-form-field">
											<label for="gn-biographical-info"><?php echo esc_html__( 'Biographical Info', 'gigneo' ); ?></label>
											<textarea id="gn-biographical-info" class="gn-textarea-counter" name="biographical_info" autocomplete="off" rows="5" placeholder="<?php echo esc_attr__( 'Enter biographical information', 'gigneo' ); ?>"><?php echo wp_kses_post( $current_login_user->description ); ?></textarea>
										</div>
									</div>
								</div>
							</fieldset>
						</div>
						<div class="gn-modal-footer">
							<input type="hidden" name="type" value="user_info">
							<button type="button" class="gn-btn gn-btn-outline-grey" data-gn-modal-close="gn-edit-user-account-info"><?php echo esc_html__( 'Close', 'gigneo' ); ?></button>
							<button type="submit" class="gn-btn gn-btn-primary"><?php echo esc_html__( 'Save', 'gigneo' ); ?></button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>