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

global $campoal_options;
global $current_user;

// common donation form 
$common_donation_form  	= isset($campoal_options['conikal_common_donation_form_field']) ? $campoal_options['conikal_common_donation_form_field'] : 0;
$common_form_id     	= isset($campoal_options['conikal_common_form_id_field']) ? $campoal_options['conikal_common_form_id_field'] : 0;

// user dashboard link
$user_dashboard_page    = isset($campoal_options['conikal_page_dashboard_user_field']) ? $campoal_options['conikal_page_dashboard_user_field'] : 0;
$user_dashboard_page    = ($user_dashboard_page ? get_permalink($user_dashboard_page) : '');

// user profile link
$user_account_page      = isset($campoal_options['conikal_page_user_account_field']) ? $campoal_options['conikal_page_user_account_field'] : 0;
$user_account_page      = ($user_account_page ? get_permalink($user_account_page) : '');

$section                = isset($_GET['section']) ? sanitize_text_field($_GET['section']) : 'dashboard';

// get user avatar
$avatar                 = conikal_get_avatar_url( $current_user->ID, array('size' => 64) );
$avatar_retina          = conikal_get_avatar_url( $current_user->ID, array('size' => 128) );
$lazy_placeholder_avatar = conikal_lazy_load_placeholder('avatar');
?>

<div class="ui <?php echo esc_attr(wp_is_mobile() ? 'right' : 'left') ?> fixed vertical secondary large menu<?php echo esc_attr(!wp_is_mobile() ? ' visible' : '') ?> overlay sidebar" id="dashboard-sidebar-menu">
    <div class="item" id="author-section">
        <h5 class="ui header">
            <img class="ui avatar image lazy" alt="<?php echo esc_attr($current_user->display_name) ?>" data-src="<?php echo esc_url($avatar) ?>" data-retina="<?php echo esc_url($avatar_retina) ?>" src="<?php echo esc_url($lazy_placeholder_avatar) ?>">
            <div class="content">
                <a class="header"><?php echo esc_html($current_user->display_name) ?></a>
                <div class="sub header">
                    <?php if ($current_user->user_country) { ?>
                        <?php echo esc_html($current_user->user_country ? $current_user->user_country : '') ?>
                    <?php } ?>
                </div>
            </div>
        </h5>
    </div>
    <a class="item<?php echo esc_attr($section == 'my_petitions' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'my_petitions'), $user_dashboard_page)) ?>" data-bjax>
    	<i class="folder icon"></i><?php esc_html_e('My Petitions', 'campoal') ?>
    </a>
    <?php if (class_exists('Give')) { ?>
    <a class="item<?php echo esc_attr($section == 'my_fundraisings' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'my_fundraisings'), $user_dashboard_page)) ?>" data-bjax>
        <i class="heart icon"></i><?php esc_html_e('My Fundraising', 'campoal') ?>
    </a>
    <?php } ?>
    <?php if (class_exists('WooCommerce')) { ?>
    <a class="item<?php echo esc_attr(is_wc_endpoint_url('orders') ? ' active' : '') ?>" href="<?php echo esc_url( wc_get_account_endpoint_url( 'orders' ) ) ?>" data-bjax>
        <i class="box icon"></i><?php esc_html_e('My Orders', 'campoal') ?>
    </a>
    <?php } ?>
    <a class="item<?php echo esc_attr($section == 'signed_petitions' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'signed_petitions'), $user_dashboard_page)) ?>" data-bjax>
    	<i class="check square icon"></i><?php esc_html_e('Signed Petitions', 'campoal') ?>
    </a>
    <a class="item<?php echo esc_attr($section == 'bookmarks' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'bookmarks'), $user_dashboard_page)) ?>" data-bjax>
    	<i class="bookmark icon"></i><?php esc_html_e('Bookmarks', 'campoal') ?>
    </a>
    <a class="item<?php echo esc_attr($section == 'users_follow' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'users_follow', 'type' => 'followers'), $user_dashboard_page)) ?>" data-bjax>
    	<i class="add user icon"></i><?php esc_html_e('Users Follow', 'campoal') ?></a>
    </a>
    <a class="item<?php echo esc_attr($section == 'topics_follow' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'topics_follow'), $user_dashboard_page)) ?>" data-bjax>
    	<i class="hashtag icon"></i><?php esc_html_e('Topics Following', 'campoal') ?>
    </a>
    <?php if (class_exists('Give')) { ?>
        <a class="item<?php echo esc_attr($section == 'contributions' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'contributions', 'type' => 'my_contributions'), $user_dashboard_page)) ?>" data-bjax>
            <i class="leaf icon"></i><?php esc_html_e('Donations', 'campoal') ?>
        </a>
        <a class="item<?php echo esc_attr($section == 'transactions' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'transactions', 'type' => (empty($common_donation_form) && empty($common_form_id)) ? 'receive' : 'send'), $user_dashboard_page)) ?>" data-bjax>
            <i class="handshake icon"></i><?php esc_html_e('Transactions', 'campoal') ?>
        </a>
        <?php if (function_exists('conikal_register_petition_type') && empty($common_donation_form) && empty($common_form_id)) { ?>
            <a class="item<?php echo esc_attr($section == 'withdrawals' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'withdrawals'), $user_dashboard_page)) ?>" data-bjax>
                <i class="undo icon"></i><?php esc_html_e('Withdrawals', 'campoal') ?>
            </a>
            <a class="item<?php echo esc_attr($section == 'financial' ? ' active' : '') ?>" href="<?php echo esc_url(add_query_arg(array('section' => 'financial'), $user_dashboard_page)) ?>" data-bjax>
                <i class="money bill alternate icon"></i><?php esc_html_e('Financial', 'campoal') ?>
            </a>
        <?php } ?>
    <?php } ?>
    <?php if (class_exists('WooCommerce')) { ?>
    <a class="item<?php echo esc_attr(is_wc_endpoint_url('downloads') ? ' active' : '') ?>" href="<?php echo esc_url( wc_get_account_endpoint_url( 'downloads' ) ) ?>" data-bjax>
        <i class="cloud download icon"></i><?php esc_html_e('Downloadable', 'campoal') ?>
    </a>
    <?php } ?>
    <a class="item" href="<?php echo esc_url($user_account_page) ?>" data-bjax>
        <i class="cog icon"></i><?php esc_html_e('Edit Profile', 'campoal') ?>
    </a>
</div>