<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $page;
global $current_user;

// Avatar upload section
if (!wp_is_mobile()) {
    get_template_part('templates/avatar-upload');
}

$user_dashboard_page    = conikal_get_assign_page('conikal_page_dashboard_user_field');
$user_account_page      = conikal_get_assign_page('conikal_page_user_account_field');

$tab = isset($_GET['tab']) ? $_GET['tab'] : 'profile';
$upload_tab = isset($_GET['upload']) ? $_GET['upload'] : 'front';

$decision_id = get_user_meta($current_user->ID, 'user_decision', true);

$menu_label_icon = conikal_profile_menu_label_icon();
?>
<div class="ui <?php echo esc_attr(wp_is_mobile() ? 'icon right labeled fluid large basic button dropdown profile-menu-dropdown' : 'vertical secondary fluid big menu') ?>" id="profile-tab">
    <?php if (wp_is_mobile()) : ?>
        <span class="text"><i class="<?php echo esc_attr($menu_label_icon->icon) ?>"></i><?php echo esc_html($menu_label_icon->label) ?></span>
        <i class="dropdown icon"></i>
        <div class="large menu">
    <?php endif; ?>
    <?php
    if ($user_dashboard_page) { ?>
    <a href="<?php echo esc_url($user_dashboard_page->link) ?>" class="item" data-bjax>
        <i class="compass icon"></i>
        <?php echo esc_html($user_dashboard_page->title) ?>
    </a>
    <?php } ?>
    <a href="<?php echo esc_url($user_account_page ? add_query_arg(array('tab' => 'profile'), $user_account_page->link) : '') ?>#profile" class="item<?php echo esc_attr(is_page_template('user-account.php') && $tab == 'profile' ? ' active' :'') ?>" <?php echo esc_attr(is_page_template('user-account.php') ? 'data-tab=profile' : '') ?>>
        <i class="user icon"></i>
        <?php esc_html_e('Edit Profile', 'campoal') ?>
    </a>
    <?php if (wp_is_mobile()) : ?>
    <a href="<?php echo esc_url($user_account_page ? add_query_arg(array('tab' => 'avatar'), $user_account_page->link) : '') ?>#avatar" class="item<?php echo esc_attr($tab == 'avatar' ? ' active' : '') ?>" <?php echo esc_attr(is_page_template('user-account.php') ? 'data-tab=avatar' : '') ?>>
        <i class="upload icon"></i>
        <?php esc_html_e('Upload avatar', 'campoal') ?>
    </a>
    <?php endif; ?>
    <a href="<?php echo esc_url($user_account_page ? add_query_arg(array('tab' => 'settings'), $user_account_page->link) : '') ?>#settings" class="item<?php echo esc_attr($tab == 'settings' ? ' active' : '') ?>" <?php echo esc_attr(is_page_template('user-account.php') ? 'data-tab=settings' : '') ?>>
        <i class="toggle on icon"></i>
        <?php esc_html_e('Preferences', 'campoal') ?>
    </a>
    <a href="<?php echo esc_url($user_account_page ? add_query_arg(array('tab' => 'password'), $user_account_page->link) : '') ?>#password" class="item<?php echo esc_attr($tab == 'password' ? ' active' : '') ?>" <?php echo esc_attr(is_page_template('user-account.php') ? 'data-tab=password' : '') ?>>
        <i class="lock icon"></i>
        <?php esc_html_e('Change Password', 'campoal') ?>
    </a>
    <?php if (class_exists('WP2FA\Shortcodes\Shortcodes') && function_exists('conikal_two_factor_form')) : ?>
    <a href="<?php echo esc_url($user_account_page ? add_query_arg(array('tab' => '2fa'), $user_account_page->link) : '') ?>#2fa" class="item<?php echo esc_attr($tab == '2fa' ? ' active' : '') ?>" <?php echo esc_attr(is_page_template('user-account.php') ? 'data-tab=2fa' : '') ?>>
        <i class="shield alternate icon"></i>
        <?php esc_html_e('2-Factor Authentication', 'campoal') ?>
    </a>
    <?php endif; ?>
    <a href="<?php echo add_query_arg( array_merge($_GET, array('tab' => 'indentify')), home_url( $wp->request ) ); ?>" class="item<?php echo esc_attr($tab == 'indentify' ? ' active' : '') ?><?php echo esc_attr(empty($decision_id) ? ' display none' : '') ?>" id="indentify-tab-link">
        <i class="address card icon"></i>
        <?php esc_html_e('Indentify documents', 'campoal') ?>
    </a>
    <?php if (class_exists('WooCommerce')) { ?>
        <a href="<?php echo esc_url( wc_get_account_endpoint_url( 'edit-address' ) ) ?>" class="item<?php echo esc_attr(is_wc_endpoint_url('edit-address') ? ' active' : '') ?>">
            <i class="home icon"></i>
            <?php esc_html_e('My Address', 'campoal') ?>
        </a>
        <a href="<?php echo esc_url( wc_get_account_endpoint_url( 'payment-methods' ) ) ?>" class="item<?php echo esc_attr(is_wc_endpoint_url('payment-methods') ? ' active' : '') ?>">
            <i class="credit card icon"></i>
            <?php esc_html_e('Payment Methods', 'campoal') ?>
        </a>
    <?php } ?>
    <a href="<?php echo wp_logout_url(home_url('/')); ?>" class="item">
        <i class="logout icon"></i>
        <?php esc_html_e('Logout', 'campoal') ?>
    </a>

    <?php if (wp_is_mobile()) : ?>
        </div>
    <?php endif; ?>
</div>