<?php
if (!defined('ABSPATH')) {
    exit;
}
$logout_url = add_query_arg(array(
    'chama-logout'       => 'true',
    'chama-logout-nonce' => wp_create_nonce('chama_logout_action'),
), home_url(add_query_arg([], chama_get_current_request_uri())));

$user = wp_get_current_user();
$is_email_verified = false;
// check	
$current_url        = home_url(chama_get_current_request_uri());
$resend_confirmation_link = '';
$email = '';
if ($user) {
    $user_id = $user->ID;
    $is_email_verified = get_user_meta($user_id, 'is_email_verified', true); // checks if the account has already been activated. We're doing this to prevent someone from logging in with an outdated confirmation link
    $display_name = $user->display_name ? $user->display_name : $user->user_login;
    $username = $user->user_login;
    $email = $user->user_email;
    $resend_confirmation_link = esc_url(add_query_arg(
        array(
            'user_id' => (int) $user->ID,
            'chama_nonce' => wp_create_nonce('chama_resend_confirmation_nonce'),
            'chama_action' => 'resend-confirmation',
        ),
        $current_url
    ));

} else {
    // invalid reqeuest
    chama_errors()->add('invalid_request', __('Invalid request.', 'chama'));
    exit;

}
?>


	<?php

// show any error messages
chama_show_error_messages();?>
   <?php 
   // phpcs:ignore WordPress.Security.NonceVerification.Recommended
   if (isset($_GET['sent-link']) && $_GET['sent-link'] == 'true') { 
    ?>
			<div class="chama-alert chama-alert-success shadow">
				<span>
                    <?php
/* translators: %s email. */
    echo sprintf(wp_kses('A confirmation email has been sent to <b>%s</b>. Make sure to click on the confirmation URL sent to your email address. This will give you full access to the content on this website.', chama_allowed_html()), esc_html($email));
    ?></span>
			</div>
		<?php
$disable = true;}?>
<?php if (!$is_email_verified) {?>
			<div class="chama-alert chama-alert-warning shadow">
				<span>
                <?php
/* translators: %s email. */
    echo sprintf(wp_kses('You have not yet verified your email address! You must click on the confirmation URL sent to your email address before you gain full access to the content on this website. <a href="%s">Resend confirmation email.</a>', chama_allowed_html()), esc_html($resend_confirmation_link));
    ?>
                    </span>
			</div>
		<?php }?>
        <div id="chama-page-content-wrapper">
        <div id="chama-page-content">

            <h3 class="chama-heading-with-avatar"> <picture>
  <source srcset="<?php print esc_url(get_avatar_url(get_current_user_id(), ['size' => '51']));?>" media="(min-width: 992px)" />
  <img class="chama-avatar" src="<?php print esc_url(get_avatar_url(get_current_user_id(), ['size' => '40']));?>" />
</picture> Welcome, <?php echo esc_html($display_name); ?></h3>
<p><b>Username:</b> <?php echo esc_html($username); ?></p>
<p><b>Email:</b> <?php echo esc_html($email); ?></p>
<p><a href="<?php echo esc_url(CHAMA_EDIT_ACCOUNT_URL); ?>">Edit Account</a> | <a href="javascript:;" class="chama-delete-account">Delete Account</a> | <a href="<?php echo esc_url(CHAMA_EDIT_PASSWORD_URL); ?>">Change Password</a> |  <a href="<?php echo esc_url($logout_url); ?>">Logout</a></p>
            </div>
</div>

<!--modal-->
<div class="chama_modal micromodal-slide" id="chama-modal" aria-hidden="true">
    <div class="chama_modal__overlay" tabindex="-1" data-micromodal-close>
      <div class="chama_modal__container" role="dialog" aria-modal="true" aria-labelledby="chama-modal-title">
        <header class="chama_modal__header">
          <h2 class="chama_modal__title" id="chama-modal-title">
          <i class="fa-solid fa-triangle-exclamation"></i> <span>Cancel</span>
          </h2>
          <button class="chama_modal__close" aria-label="Close modal" data-micromodal-close></button>
        </header>
        <main class="chama_modal__content" id="chama-modal-content">
        <div id="chama-transaction-errors" role="alert" class="chama-alert chama-alert-error"></div>
          <p id="chama-modal-warning">
          </p>
        </main>
        <footer class="chama_modal__footer">
          <button id="chama-confirm-deletion" class="chama_modal__btn chama_modal_btn_red"><i class="chama-button-spinner fa-solid fa-circle-notch fa-spin chama-hide"></i>Yes, delete</button>
          <button id="chama-modal-close" class="chama_modal__btn" data-micromodal-close aria-label="Close this dialog window">Nevermind</button>
          <?php wp_nonce_field('wp_rest')?>
          <?php wp_nonce_field('chama_logout_action', 'chama_logout_nonce'); ?>
          <input type="hidden" id="chama_base_rest_url" name="chama_base_rest_url" value="<?php echo esc_url(get_rest_url(null, '/')); ?>" />
        </footer>
      </div>
    </div>
  </div>



