<?php
/*
Template Name: User Account
*/

/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;
global $post;
global $current_user;
global $wp;

// Check user is loggedin or not, if not redirect to login page
conikal_redirect_login();

get_header();

$show_bc = isset($campoal_options['conikal_breadcrumbs_field']) ? $campoal_options['conikal_breadcrumbs_field'] : 0;

$decision_id = get_user_meta($current_user->ID, 'user_decision', true);
if ($decision_id) {
    $prefix = 'decisionmaker_';
    $decision_status        = get_post_status( $decision_id );
} else {
    $decision_status        = '';
}

$tab = isset($_GET['tab']) ? $_GET['tab'] : 'profile';
?>
<div class="wrapper profile">
<div class="ui container">
    <?php if($show_bc == 1) {
        conikal_petition_breadcrumbs();
    } else {
        print '<div class="none-breadcrumb"></div>';
    } ?>
    <div class="page content">
        <div class="ui grid">
            <div class="sixteen wide mobile five wide tablet four wide computer column">
                <?php if ($tab != 'indentify') :
                    // Profile menu section
                    get_template_part('templates/profile/profile-menu');
                     ?>
                <?php else: ?>
                    <div class="ui vertical secondary fluid big menu" id="profile-tab">
                        <a href="<?php echo add_query_arg( array_merge($_GET, array('tab' => 'profile')), home_url( $wp->request ) ); ?>" class="item<?php echo esc_attr($tab == 'profile' ? ' active' : '') ?>">
                            <i class="user icon"></i>
                            <?php esc_html_e('Back to profile', 'campoal') ?>
                        </a>
                    </div>
                <?php endif; ?>

            </div>
            <div class="sixteen wide mobile eleven wide tablet nine wide computer column" id="content<?php echo esc_attr($post->ID) ?>">
                <?php while(have_posts()) : the_post(); ?>
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <?php if ($decision_status == 'pending') { ?>
                        <div id="decision_status">
                            <div class="ui warning message">
                                <i class="warning icon"></i>
                                <?php esc_html_e('Decision maker account confirmation is pending approval!', 'campoal') ?>
                            </div>
                        </div>
                    <?php } ?>
                    <!-- tab profile info -->
                    <div id="up_response" class="respon-message"></div>
                    <div class="ui tab<?php echo esc_attr($tab == 'profile' ? ' active' : '') ?>" data-tab="profile">
                        <h1 class="ui dividing header"><?php esc_html_e('Edit Profile', 'campoal'); ?></h1>
                        <?php get_template_part('templates/profile/profile-info'); ?>
                    </div>
                    <!-- tab profile info -->

                    <!-- tab avatar-->
                    <?php if (wp_is_mobile()) : ?>
                        <div class="ui tab<?php echo esc_attr($tab == 'avatar' ? ' active' : '') ?>" data-tab="avatar">
                            <h1 class="ui dividing header"><?php esc_html_e('Upload avatar', 'campoal') ?></h1>
                            <?php get_template_part('templates/avatar-upload'); ?>
                            
                            <!-- save button -->
                            <div class="ui basic vertical right aligned segment">
                                <button class="ui right labeled icon large primary button updateProfileBtn"><i class="save icon"></i><?php esc_html_e('Save Avatar', 'campoal'); ?></button>
                            </div>
                        </div>
                    <?php endif; ?>
                    
                    <!-- tab settings-->
                    <div class="ui tab<?php echo esc_attr($tab == 'settings' ? ' active' : '') ?>" data-tab="settings">
                        <h1 class="ui dividing header"><?php esc_html_e('Account settings', 'campoal') ?></h1>
                        <?php get_template_part('templates/profile/settings'); ?>
                    </div>

                    <!-- tab reset password -->
                    <div class="ui tab<?php echo esc_attr($tab == 'password' ? ' active' : '') ?>" data-tab="password">
                        <h1 class="ui dividing header"><?php esc_html_e('Change password', 'campoal') ?></h1>
                        <?php get_template_part('templates/profile/reset-password'); ?>
                        </div>
                    <!-- tab reset password -->

                    <!-- tab 2 factor authentication -->
                    <div class="ui tab<?php echo esc_attr($tab == '2fa' ? ' active' : '') ?>" data-tab="2fa">
                        <h1 class="ui dividing header"><?php esc_html_e('2-Factor Authentication', 'campoal') ?></h1>
                        <?php get_template_part('templates/profile/2factor-authentication'); ?>
                    </div>
                    <!-- tab 2 factor authentication -->

                    <!-- tab indentify document -->
                    <?php if ($tab == 'indentify' && $decision_id) : ?>
                    <div class="ui tab<?php echo esc_attr($tab == 'indentify' ? ' active' : '') ?>" data-tab="indentify">
                        <h1 class="ui dividing header"><?php esc_html_e('Indentify documents', 'campoal') ?></h1>
                        <?php get_template_part('templates/profile/indentify-document'); ?>
                    </div>
                    <!-- tab indentify document -->
                    <?php endif; ?>
                    
                </div>
                <?php endwhile; ?>
            </div>
            <div class="three wide computer sixteen wide tablet sixteen wide mobile column computer only profile-tips-section">
                <!-- profile tips sticky -->
                <?php get_template_part('templates/profile/profile-tips'); ?>
            </div>
        </div>
    </div>
</div>

<!-- Detele account confirm modal -->
<?php get_template_part('templates/profile/delete-account'); ?>

<?php wp_nonce_field('user_profile_ajax_nonce', 'securityUserProfile', true); ?>
<?php wp_nonce_field('resend_ajax_nonce', 'securityResendVerification', true); ?>
</div>
<?php get_footer(); ?>