<?php
if (!defined('ABSPATH')) {
    exit;
}
$templates = new Chama_Template_Loader;
$header_url = get_option('chama_header');
$avatar_url = get_option('chama_avatar') ? get_option('chama_avatar') : CHAMA_ASSETS_URL . 'img/chama-avatar.jpg';
$name = get_option('chama_name');
$bio = get_option('chama_introduction');
$display_donor_analytics = get_option('chama_display_donor_analytics');
$display_member_analytics = get_option('chama_display_member_analytics');
$display_funder_analytics = get_option('chama_display_funder_analytics');
$display_commissioner_analytics = get_option('chama_display_commissioner_analytics');
$display_hub_page = get_option('chama_display_hub');
$display_donate_page = get_option('chama_display_donate') && CHAMA_DONATE_URL;
$display_membership_page = get_option('chama_display_membership');
$display_crowdfunding_page = get_option('chama_display_crowdfunding');
$display_commissions_page = get_option('chama_display_commissions');
$donor_total = get_option('chama_total_donors') ? get_option('chama_total_donors') : 0;
$member_total = get_option('chama_total_members') ? get_option('chama_total_members') : 0;
$funder_total = get_option('chama_total_funders') ? get_option('chama_total_funders') : 0;
$commissioner_total = get_option('chama_total_commissioners') ? get_option('chama_total_commissioners') : 0;

$pages_list = chama_get_active_pages();
$current_id = get_the_ID();

// check	
$current_url        = home_url(chama_get_current_request_uri());
$social_url = $social_title = $facebook_url = $x_url = $whatsapp_url = $linkedin_url = '' ;
?>

<div class="chama-page-wrapper">
<div id="chama-header">
    <figure class="chama-figure chama-header-img">
        <?php if ($header_url): ?>
        <img src="<?php echo esc_attr($header_url); ?>">
        <?php endif;?>
    </figure>
    <figure class="chama-figure chama-avatar-wrapper">
        <span class="chama-avatar" style="background-image: url('<?php echo esc_attr($avatar_url); ?>')"></span>
    </figure>
    <?php if($display_donate_page): ?>
    <div class="chama-header-actions">
        <a title="Donate" href="<?php echo esc_attr(CHAMA_DONATE_URL); ?>" class="chama-button chama-button-medium" role="button"><i class='fa-solid fa-hand-holding-heart'></i>&nbsp;&nbsp;Donate</a>
        <a href="javascript:;" class="chama-share-button chama-button" title="Share this page">
        <i class="fa-solid fa-arrow-up-from-bracket"></i>
  </a>
  <div class="chama-share-dropdown-menu">
    <div class="chama-share-dropdown-wrapper">
  <span class="chama-share-commission">Share this: <?php $templates->get_template_part('content', 'socialsharebuttons'); ?></span>
  </div>
</div>
    </div>
  

    <?php endif;?>
    <div class="chama-header-meta">
        <div class="chama-header-name"><?php echo esc_html($name); ?></div>

        <div class="chama-header-bio">
        <?php echo esc_html($bio); ?>
        </div>
        <div class="chama-header-analytics">
            <ul>
            <li class="<?php echo $display_donor_analytics ? '' : 'chama-hide'; ?>"><b><?php echo esc_html($donor_total); ?></b> <span class="chama-lighter-text">Donors</span></li>
            <li class="<?php echo $display_member_analytics ? '' : 'chama-hide'; ?>"><b><?php echo esc_html($member_total); ?></b> <span class="chama-lighter-text">Members</span></li>
            <li class="<?php echo $display_funder_analytics ? '' : 'chama-hide'; ?>"><b><?php echo esc_html($funder_total); ?></b> <span class="chama-lighter-text">Funders</span></li>
            <li class="<?php echo $display_commissioner_analytics ? '' : 'chama-hide'; ?>"><b><?php echo esc_html($commissioner_total); ?></b> <span class="chama-lighter-text">Commissioners</span></li>
            </ul>
        </div>
    </div>
    <hr class="chama-header-line">
    <ul id="chama-header-nav">
        <?php foreach ($pages_list as $page): ?>
        <li class="chama-nav-item <?php echo esc_attr($current_id === $page['id'] ? 'active' : ''); ?>">
        <a class="chama-nav-link" href="<?php echo esc_url($page['link']); ?>" title="<?php echo esc_attr($page['title']); ?>"><?php echo esc_html($page['title']); ?></a>
        </li>
        <?php endforeach;?>
    </ul>
    

</div>

