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

global $campoal_options;
global $current_user;

$copyright              = isset($campoal_options['conikal_copyright_field']) ? $campoal_options['conikal_copyright_field'] : '';
$search_bar             = isset($campoal_options['conikal_search_bar_field']) ? $campoal_options['conikal_search_bar_field'] : 'hidden';
$country_selection_mode = isset($campoal_options['conikal_country_selection_mode_field']) ? $campoal_options['conikal_country_selection_mode_field'] : 0;
$submit_button          = isset($campoal_options['conikal_submit_button_field']) ? $campoal_options['conikal_submit_button_field'] : 0;
$login_link_mobile      = isset($campoal_options['conikal_login_link_mobile_field']) ? $campoal_options['conikal_login_link_mobile_field'] : 1;
$button_classes         = 'primary button submit-petition-btn';

$submit_button_page     = conikal_get_assign_page('conikal_submit_button_link_field');
$submit_button_id       = ($submit_button_page ? $submit_button_page->id : '');
$submit_button_title    = ($submit_button_page ? $submit_button_page->title : esc_html__('Start a petition', 'campoal'));
$submit_button_link     = ($submit_button_page ? $submit_button_page->link : '');

// 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(is_rtl() ? 'right' : 'left') ?> vertical huge menu sidebar leftside-menu" id="leftside-menu">
    <?php if ($search_bar != 'hidden') { ?>
    <div class="item searchBtnMobile">
        <div class="ui search">
            <div class="ui icon fluid transparent large input">
              <input class="prompt" type="text" placeholder="<?php esc_attr_e('Search...', 'campoal') ?>">
              <i class="search icon"></i>
            </div>
        </div>
    </div>
    <?php } ?>

    <?php if (is_user_logged_in()) : ?>
    <div class="item" id="author-section">
        <div class="ui small 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>
        </div>
    </div>
    <?php endif; ?>

    <?php 
    if(is_user_logged_in()) {
        if ($submit_button == 1) { ?>
            <form action="<?php echo esc_url($submit_button_link); ?>" class="item">
                <button class="ui fluid <?php echo esc_attr($button_classes) ?>"><?php echo conikal_custom_icon('submit') ?> <?php echo esc_html($submit_button_title); ?></button>
            </form>
    <?php } 
    } else {
        if ($submit_button == 1) { ?>
            <div class="item">
                <a href="<?php echo esc_attr($submit_button_page && $login_link_mobile == 1 ? esc_url($submit_button_page->link) : 'javascript:void(0)') ?>" 
                    class="ui fluid <?php echo esc_attr($button_classes) ?><?php echo esc_attr($submit_button_page && $login_link_mobile == 1 ? '' : ' submit-signin-btn') ?>" 
                    data-id="<?php echo esc_attr($submit_button_id) ?>">
                    <?php echo conikal_custom_icon('submit') ?> 
                    <?php echo esc_html($submit_button_title); ?>
                </a>
            </div>
    <?php }
    } ?>

    <?php if ( function_exists( 'conikal_header_cart' ) ) { 
        conikal_header_cart();
    } ?>
    
    <?php conikal_custom_menu_mobile('mobile') ?>

    <div class="item">
        <?php get_template_part('templates/header/country-selection') ?>
    </div>

    <div class="item">
        <?php get_template_part('templates/header/language-selection') ?>
    </div>
</div>