<?php
$bosa_resort_popular_brandsoneID 			= get_theme_mod( 'bosa_resort_brands_image_one', '' );
$bosa_resort_popular_brandscategoryone 		= get_theme_mod( 'bosa_resort_brand_category_one', '' );

$bosa_resort_popular_brandstwoID 			= get_theme_mod( 'bosa_resort_brands_image_two','');
$bosa_resort_popular_brandscategorytwo 		= get_theme_mod( 'bosa_resort_brand_category_two', '' );

$bosa_resort_popular_brandsthreeID 			= get_theme_mod( 'bosa_resort_brands_image_three', '' );
$bosa_resort_popular_brandscategorythree 	= get_theme_mod( 'bosa_resort_brand_category_three', '' );

$bosa_resort_popular_brandsfourID 			= get_theme_mod( 'bosa_resort_brands_image_four', '' );
$bosa_resort_popular_brandscategoryfour 	= get_theme_mod( 'bosa_resort_brand_category_four', '' );

$bosa_resort_popular_brandsfiveID 			= get_theme_mod( 'bosa_resort_brands_image_five', '' );
$bosa_resort_popular_brandscategoryfive 	= get_theme_mod( 'bosa_resort_brand_category_five', '' );

$bosa_resort_popular_brandssixID 			= get_theme_mod( 'bosa_resort_brands_image_six', '' );
$bosa_resort_popular_brandscategorysix 		= get_theme_mod( 'bosa_resort_brand_category_six', '' );


$bosa_resort_popular_brand_array = array();
$bosa_resort_has_brands = false;
if( !empty( $bosa_resort_popular_brandsoneID ) || !empty( $bosa_resort_popular_brandscategoryone ) ){
	$bosa_resort_popular_brand_one  = wp_get_attachment_image_src( $bosa_resort_popular_brandsoneID ,'bosa-resort-420-300');
 	if ( is_array(  $bosa_resort_popular_brand_one ) ){
 		$bosa_resort_has_brands = true;
   	 	$bosa_resort_popular_brands_one = $bosa_resort_popular_brand_one[0];
   	 	$bosa_resort_popular_brand_array['image_one'] ['ID'] = $bosa_resort_popular_brands_one;	 	
  	}
  	if ( !empty($bosa_resort_popular_brandscategoryone) ){
 		$bosa_resort_has_brands = true;
   	 	$bosa_resort_popular_brand_array['image_one']['category'] = $bosa_resort_popular_brandscategoryone;	
  	}
}
if( !empty( $bosa_resort_popular_brandstwoID ) || !empty( $bosa_resort_popular_brandscategorytwo ) ){
	$bosa_resort_popular_brand_two = wp_get_attachment_image_src( $bosa_resort_popular_brandstwoID,'bosa-resort-420-300');
	if ( is_array(  $bosa_resort_popular_brand_two ) ){
		$bosa_resort_has_brands = true;	
        $bosa_resort_popular_brands_two = $bosa_resort_popular_brand_two[0];
        $bosa_resort_popular_brand_array['image_two'] ['ID']= $bosa_resort_popular_brands_two; 
	}
	if ( !empty($bosa_resort_popular_brandscategorytwo) ){
		$bosa_resort_has_brands = true;
	 	$bosa_resort_popular_brand_array['image_two']['category'] = $bosa_resort_popular_brandscategorytwo;	
  	}
}
if( !empty( $bosa_resort_popular_brandsthreeID ) || !empty( $bosa_resort_popular_brandscategorythree ) ){	
	$bosa_resort_popular_brand_three = wp_get_attachment_image_src( $bosa_resort_popular_brandsthreeID,'bosa-resort-420-300');
	if ( is_array(  $bosa_resort_popular_brand_three ) ){
		$bosa_resort_has_brands = true;
      	$bosa_resort_popular_brands_three = $bosa_resort_popular_brand_three[0];
      	$bosa_resort_popular_brand_array['image_three'] ['ID']= $bosa_resort_popular_brands_three;		
  	}
  	if ( !empty($bosa_resort_popular_brandscategorythree) ){
		$bosa_resort_has_brands = true;
	 	$bosa_resort_popular_brand_array['image_three'] ['category'] = $bosa_resort_popular_brandscategorythree;	
  	}
}
if( !empty( $bosa_resort_popular_brandsfourID ) || !empty( $bosa_resort_popular_brandscategoryfour ) ){	
	$bosa_resort_popular_brand_four = wp_get_attachment_image_src( $bosa_resort_popular_brandsfourID,'bosa-resort-420-300');
	if ( is_array(  $bosa_resort_popular_brand_four ) ){
		$bosa_resort_has_brands = true;
      	$bosa_resort_popular_brands_four = $bosa_resort_popular_brand_four[0];
      	$bosa_resort_popular_brand_array['image_four'] ['ID'] = $bosa_resort_popular_brands_four;	
  	}
  	if ( !empty($bosa_resort_popular_brandscategoryfour) ){
		$bosa_resort_has_brands = true;
	 	$bosa_resort_popular_brand_array['image_four'] ['category'] = $bosa_resort_popular_brandscategoryfour;	
  	}
}
if( !empty( $bosa_resort_popular_brandsfiveID ) || !empty( $bosa_resort_popular_brandscategoryfive ) ){	
	$bosa_resort_popular_brand_five = wp_get_attachment_image_src( $bosa_resort_popular_brandsfiveID,'bosa-resort-420-300');
	if ( is_array(  $bosa_resort_popular_brand_five ) ){
		$bosa_resort_has_brands = true;
      	$bosa_resort_popular_brands_five = $bosa_resort_popular_brand_five[0];
      	$bosa_resort_popular_brand_array['image_five'] ['ID'] = $bosa_resort_popular_brands_five;	
  	}
  	if ( !empty($bosa_resort_popular_brandscategoryfive) ){
		$bosa_resort_has_brands = true;
	 	$bosa_resort_popular_brand_array['image_five'] ['category'] = $bosa_resort_popular_brandscategoryfive;	
  	}
}
if( !empty( $bosa_resort_popular_brandssixID ) || !empty( $bosa_resort_popular_brandscategorysix ) ){	
	$bosa_resort_popular_brand_six = wp_get_attachment_image_src( $bosa_resort_popular_brandssixID,'bosa-resort-420-300');
	if ( is_array(  $bosa_resort_popular_brand_six ) ){
		$bosa_resort_has_brands = true;
      	$bosa_resort_popular_brands_six = $bosa_resort_popular_brand_six[0];
      	$bosa_resort_popular_brand_array['image_six'] ['ID'] = $bosa_resort_popular_brands_six;	
  	}
  	if ( !empty($bosa_resort_popular_brandscategorysix) ){
		$bosa_resort_has_brands = true;
	 	$bosa_resort_popular_brand_array['image_six'] ['category'] = $bosa_resort_popular_brandscategorysix;	
  	}
}

$bosa_resort_product_cat = bosa_resort_get_post_categories();

if( !get_theme_mod( 'bosa_resort_disable_popular_brands_section', true ) && ( $bosa_resort_has_brands || get_theme_mod('bosa_resort_popular_brands_title') || get_theme_mod('bosa_resort_popular_brands_sub_title') ) ){ ?>
	<section class="section-popular-brand-area">
		<?php if( get_theme_mod('bosa_resort_popular_brands_title') || get_theme_mod('bosa_resort_popular_brands_sub_title') ){ ?>
			<div class="section-title-wrap col-lg-6 col-md-8 offset-lg-3 offset-md-2">
				<h2 class="brand-section-title">	
					<?php echo esc_html( get_theme_mod('bosa_resort_popular_brands_title') ); ?>
				</h2>
				<p>
					<?php echo esc_html( get_theme_mod('bosa_resort_popular_brands_sub_title') ); ?>
				</p>
			</div>
		<?php } ?>
		<div class="content-wrap">
			<?php foreach( $bosa_resort_popular_brand_array as $bosa_resort_each_popular_brands ){ ?>
				<article class="leading-items">
					<?php if ( isset( $bosa_resort_each_popular_brands['ID'] )  && !empty( $bosa_resort_each_popular_brands['ID'] ) ){ 
							$bosa_resort_cat_url = '';
							if( isset( $bosa_resort_each_popular_brands['category'] ) && !empty( $bosa_resort_each_popular_brands['category'] ) ) {
								$bosa_resort_cat_url = $bosa_resort_each_popular_brands['category'];
							}
						?>
						<figure class= "featured-image">
							<a href="<?php echo esc_url( get_category_link( $bosa_resort_cat_url ) ); ?>">
								<img src="<?php echo esc_url( $bosa_resort_each_popular_brands['ID'] ); ?>">
							</a>	
						</figure>
					<?php } ?>
					<?php if ( isset( $bosa_resort_each_popular_brands['category'] ) && !empty( $bosa_resort_each_popular_brands['category'] ) ){ ?>
						<h5 class="entry-title">
							<a href="<?php echo esc_url( get_category_link( $bosa_resort_each_popular_brands ['category'] ) ); ?>">
								<?php echo esc_html($bosa_resort_product_cat[$bosa_resort_each_popular_brands['category'] ] ); ?>
							</a>	
						</h5>
					<?php } ?>
				</article>	
			<?php } ?>
		</div>
	</section>
<?php } 

