<?php
/**
 * Banner Categories.
 *
 */

/* ============== ListingPro Banner Categories ============ */

if (!function_exists('listingpro_banner_categories')) {
    
    function listingpro_banner_categories()
    {
        global $listingpro_options;
        $home_banner_taxonomy = '';
        if (isset($listingpro_options['home_banner_taxonomy'])) {
            $home_banner_taxonomy = $listingpro_options['home_banner_taxonomy'];
        }
        $banner_tax      = 'home_banner_cats';
        $banner_tax_slug = 'listing-category';
        if ($home_banner_taxonomy == 'tax_locs') {
            $banner_tax      = 'home_banner_locs';
            $banner_tax_slug = 'location';
        }
        if ($home_banner_taxonomy == 'tax_feats') {
            $banner_tax      = 'home_banner_feats';
            $banner_tax_slug = 'features';
        }
        
        if (isset($listingpro_options[$banner_tax])) {
            $homeBannerCategory = $listingpro_options[$banner_tax];
        } else {
            $homeBannerCategory = '';
        }
        
        
        $search_view                      = $listingpro_options['search_views'];
        $search_layout                    = $listingpro_options['search_layout'];
        $alignment                        = $listingpro_options['search_alignment'];
        $top_banner_styles                = $listingpro_options['top_banner_styles'];
        $cat_txt                          = $listingpro_options['cat_txt'];
        $differentcats_views              = $listingpro_options['categories_different_styles'];
        $bannercats_search_overlap        = $listingpro_options['categories_different_styles_search_overlap'];
        $bannercat_category_inside        = $listingpro_options['categories_different_styles_category_inside'];
        $bannercat_search_inside          = $listingpro_options['categories_different_styles_search_inside'];
        $addclass_for_tranparent_cat_view = '';
        $newbannercatClass                = '';
        $class_for_cat_uper               = '';
        $class_for_search_inside          = '';
        if ($top_banner_styles == 'banner_view') {
            if ($differentcats_views == 'category_view1') {
                $addclass_for_tranparent_cat_view = 'banner-default-view-category1';
            } elseif ($differentcats_views == 'category_view2') {
                $addclass_for_tranparent_cat_view = 'banner-default-view-category2';
            } elseif ($differentcats_views == 'category_view3') {
                $addclass_for_tranparent_cat_view = 'banner-default-view-category3';
            }elseif ($bannercats_search_overlap == 'category_view') {
                $newbannercatClass = 'new-banner-category-view4';
            }
        } elseif ($top_banner_styles == 'banner_view_search_bottom') {
            if ($bannercats_search_overlap == 'category_view') {
                $newbannercatClass = 'new-banner-category-view';
            } elseif ($bannercats_search_overlap == 'category_view1') {
                $newbannercatClass = 'new-banner-category-view1';
            } elseif ($bannercats_search_overlap == 'category_view2') {
                $newbannercatClass = 'new-banner-category-view2';
            } elseif ($bannercats_search_overlap == 'category_view3') {
                $newbannercatClass = 'new-banner-category-view3';
            }
        } elseif ($top_banner_styles == 'banner_view_category_upper') {
            if ($bannercat_category_inside == 'category_view') {
                $class_for_cat_uper = 'lp-upper-cat-view1';
            } elseif ($bannercat_category_inside == 'category_view1') {
                $class_for_cat_uper = 'lp-upper-cat-view4';
            } elseif ($bannercat_category_inside == 'category_view2') {
                $class_for_cat_uper = 'lp-upper-cat-view3';
            } elseif ($bannercat_category_inside == 'category_view3') {
                $class_for_cat_uper = 'lp-upper-cat-view2';
                $addclass_for_tranparent_cat_view   =   'category-view-bg-transparent';
            }
        } elseif ($top_banner_styles == 'banner_view_search_inside') {
            if ($bannercat_search_inside == 'category_view') {
                $class_for_search_inside = 'lp-inside-search-view';
            } elseif ($bannercat_search_inside == 'category_view1') {
                $class_for_search_inside = 'lp-inside-search-view1';
            } elseif ($bannercat_search_inside == 'category_view2') {
                $class_for_search_inside = 'lp-inside-search-view2';
            } elseif ($bannercat_search_inside == 'category_view3') {
                $class_for_search_inside = 'lp-inside-search-view3';
            }
        }
        $alignClass = '';
        if ($alignment == 'align_top') {
            $alignClass = 'lp-align-top';
        } elseif ($alignment == 'align_middle') {
            $alignClass = 'lp-align-underBanner';
        } elseif ($alignment == 'align_bottom') {
            $alignClass = 'lp-align-bottom';
        }
        
        
        $output = '';
        if (isset($homeBannerCategory) && !empty($homeBannerCategory)) {
            $output .= '<div class="lp-section-row margin-bottom-60">';
            $output .= '<div class="container">';
            $output .= '<div class="row">';
            $output .= '<div class="col-md-12">';
            if ($top_banner_styles == 'map_view') {
                if ($alignment == 'align_middle' || $alignment == 'align_bottom') {
                    $output .= '<div class="col-md-8 col-xs-12 col-md-offset-2 col-sm-offset-0">                                                                    <div class="text-center lp-search-description">                                                                        <p>' . $cat_txt . '</p>                                                                        <img src="' . get_template_directory_uri() . '/assets/images/banner-arrow-dark.png" alt="banner-arrow" class="banner-arrow">                                                                    </div>                                                                </div>';
                }
            }
            $output .= '<ul class="lp-home-categoires padding-left-0 ' . $newbannercatClass . ' ' . $class_for_cat_uper . ' ' . $class_for_search_inside . ' ' . $addclass_for_tranparent_cat_view . '">';
            $ucat       = array(
                'post_type' => 'listing',
                'hide_empty' => false,
                'include' => $homeBannerCategory
            );
            $categories = get_terms($banner_tax_slug, $ucat);
            foreach ($categories as $category) {
                $category_image = listing_get_tax_meta($category->term_id, 'category', 'image2');
                if (empty($category_image)) {
                    $category_image = listing_get_tax_meta($category->term_id, 'category', 'image');
                }
                $output .= '<li>';
                $output .= '<a href="' . get_term_link($category, $banner_tax_slug) . '" class="lp-border-radius-5">';
                $output .= '<span>';
                if (!empty($category_image) && $banner_tax_slug == 'listing-category') {
                    if ($top_banner_styles == 'banner_view_search_bottom' && $bannercats_search_overlap == 'category_view2') {
                        $output .= '<p id="cat-img-bg"><img class="icon icons-banner-cat" src="' . $category_image . '" alt="Food" /></p><br>';
                    } elseif ($top_banner_styles == 'banner_view_category_upper' && $bannercat_category_inside == 'category_view2') {
                        $output .= '<p id="cat-img-bg"><img class="icon icons-banner-cat" src="' . $category_image . '" alt="Food" /></p><br>';
                    } elseif ($top_banner_styles == 'banner_view_search_inside' && $bannercat_search_inside == 'category_view2') {
                        $output .= '<p id="cat-img-bg"><img class="icon icons-banner-cat" src="' . $category_image . '" alt="Food" /></p><br>';
                    } elseif ($top_banner_styles == 'banner_view' && $differentcats_views == 'category_view2') {
                        $output .= '<p id="cat-img-bg"><img class="icon icons-banner-cat" src="' . $category_image . '" alt="Food" /></p><br>';
                    } else {
                        $output .= '<img class="icon icons-banner-cat" src="' . $category_image . '" alt="Food" /><br>';
                    }
                } elseif ($banner_tax_slug == 'location') {
                    $output .= '<img class="icon icons-banner-cat" src="data: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GUzJ4dJOpEHQpycxekOWqslm3CBLJ0/7oIHwyjfJ+X0BgQ5R7nmBo3wl1KKBfK0hf3tv6PccHx6I+gTAl2ubBuGY23qan9JJXxAoGMINtdkCA57VjIJnxDsNmXcEBxX6IKaLQvZLsoirh8ejN06POEb8rXb4uzm/bph/yd0eKIICPhdZV0X7D9RhyaKgIAfUdY1Yd+9OixRFOQ8IYu7Njwg63RYokgI2ia21UOc61rFhv3mK/BaxL1yTyzwgNRcdze9fjQRwp6q3LuFfd7R7omiIeyzqB5ny/Pzp7V7ohkQeI8v7Pw8TYJrJgT+mbKvCj+foV0TzYDAa31CziTtmmgGPCCvKPjucPqo1kSD8IA8Rug7eqg0uySRKCF9+vwHhjkObk6K/yoAAAAASUVORK5CYII="><br>';
                } elseif ($banner_tax_slug == 'features') {
	                $icon = listingpro_get_term_meta( $category->term_id ,'lp_features_icon');
	                if(!empty($icon)) {
		                $output .= '<i class="fa '.esc_attr($icon).'"></i>';
	                }else {
		                $output .= '<i class="fa fa-check"></i>';
	                }
                }
                $output .= $category->name;
                $output .= '</span>';
                $output .= '</a>';
                $output .= '</li>';
            }
            $output .= '</ul>';
            $output .= '</div>';
            $output .= '</div>';
            $output .= '</div>';
            $output .= '</div>';
        }
        return $output;
    }
    
}