<?php
$bosa_insurance_agency_departmentsoneID = get_theme_mod( 'bosa_insurance_agency_department_image_one', '' );
$bosa_insurance_agency_departmentsone = get_theme_mod( 'bosa_insurance_agency_department_one', '' );

$bosa_insurance_agency_departmentstwoID = get_theme_mod( 'bosa_insurance_agency_department_image_two', '' );
$bosa_insurance_agency_departmentstwo = get_theme_mod( 'bosa_insurance_agency_department_two', '' );

$bosa_insurance_agency_departmentsthreeID = get_theme_mod( 'bosa_insurance_agency_department_image_three', '' );
$bosa_insurance_agency_departmentsthree = get_theme_mod( 'bosa_insurance_agency_department_three', '' );

$bosa_insurance_agency_departmentsfourID = get_theme_mod( 'bosa_insurance_agency_department_image_four', '' );
$bosa_insurance_agency_departmentsfour = get_theme_mod( 'bosa_insurance_agency_department_four', '' );

$bosa_insurance_agency_departmentsfiveID = get_theme_mod( 'bosa_insurance_agency_department_image_five', '' );
$bosa_insurance_agency_departmentsfive = get_theme_mod( 'bosa_insurance_agency_department_five', '' );

$bosa_insurance_agency_departmentssixID = get_theme_mod( 'bosa_insurance_agency_department_image_six', '' );
$bosa_insurance_agency_departmentssix = get_theme_mod( 'bosa_insurance_agency_department_six', '' );

$bosa_insurance_agency_departmentssevenID = get_theme_mod( 'bosa_insurance_agency_department_image_seven', '' );
$bosa_insurance_agency_departmentsseven = get_theme_mod( 'bosa_insurance_agency_department_seven', '' );

$bosa_insurance_agency_departmentseightID = get_theme_mod( 'bosa_insurance_agency_department_image_eight', '' );
$bosa_insurance_agency_departmentseight = get_theme_mod( 'bosa_insurance_agency_department_eight', '' );

$bosa_insurance_agency_departmentsnineID = get_theme_mod( 'bosa_insurance_agency_department_image_nine', '' );
$bosa_insurance_agency_departmentsnine = get_theme_mod( 'bosa_insurance_agency_department_nine', '' );


$bosa_insurance_agency_category_product_one_array = array();
$bosa_insurance_agency_category_product_two_array = array();
$bosa_insurance_agency_category_product_three_array = array();
$bosa_insurance_agency_has_product_one = false;
$bosa_insurance_agency_has_product_two = false;
$bosa_insurance_agency_has_product_three = false;
if( !empty( $bosa_insurance_agency_departmentsoneID ) || !empty( $bosa_insurance_agency_departmentsone ) ){
	$bosa_insurance_agency_category_product_one = wp_get_attachment_image_src( $bosa_insurance_agency_departmentsoneID ,'bosa-insurance-agency-1370-550');
 	if ( is_array( $bosa_insurance_agency_category_product_one ) ){
 		$bosa_insurance_agency_has_product_one = true;
   	 	$bosa_insurance_agency_category_products_one = $bosa_insurance_agency_category_product_one[0];
   	 	$bosa_insurance_agency_category_product_one_array['image_one'] ['ID'] = $bosa_insurance_agency_category_products_one;	 	
  	}
  	if ( !empty( $bosa_insurance_agency_departmentsone ) ){
 		$bosa_insurance_agency_has_product_one = true;
   	 	$bosa_insurance_agency_category_product_one_array['image_one']['category'] = $bosa_insurance_agency_departmentsone;	
  	}
}
if( !empty( $bosa_insurance_agency_departmentstwoID ) || !empty( $bosa_insurance_agency_departmentstwo ) ){
	$bosa_insurance_agency_category_product_two = wp_get_attachment_image_src( $bosa_insurance_agency_departmentstwoID ,'bosa-insurance-agency-420-300');
 	if ( is_array( $bosa_insurance_agency_category_product_two ) ){
 		$bosa_insurance_agency_has_product_two = true;
   	 	$bosa_insurance_agency_category_products_two = $bosa_insurance_agency_category_product_two[0];
   	 	$bosa_insurance_agency_category_product_two_array['image_two'] ['ID'] = $bosa_insurance_agency_category_products_two;	 	
  	}
  	if ( !empty( $bosa_insurance_agency_departmentstwo ) ){
 		$bosa_insurance_agency_has_product_two = true;
   	 	$bosa_insurance_agency_category_product_two_array['image_two']['category'] = $bosa_insurance_agency_departmentstwo;	
  	}
}
if( !empty( $bosa_insurance_agency_departmentsthreeID ) || !empty( $bosa_insurance_agency_departmentsthree ) ){
	$bosa_insurance_agency_category_product_three = wp_get_attachment_image_src( $bosa_insurance_agency_departmentsthreeID ,'bosa-insurance-agency-420-300');
 	if ( is_array( $bosa_insurance_agency_category_product_three ) ){
 		$bosa_insurance_agency_has_product_two = true;
   	 	$bosa_insurance_agency_category_products_three = $bosa_insurance_agency_category_product_three[0];
   	 	$bosa_insurance_agency_category_product_two_array['image_three'] ['ID'] = $bosa_insurance_agency_category_products_three;	 	
  	}
  	if ( !empty( $bosa_insurance_agency_departmentsthree ) ){
 		$bosa_insurance_agency_has_product_two = true;
   	 	$bosa_insurance_agency_category_product_two_array['image_three']['category'] = $bosa_insurance_agency_departmentsthree;	
  	}
}
if( !empty( $bosa_insurance_agency_departmentsfourID ) || !empty( $bosa_insurance_agency_departmentsfour ) ){
	$bosa_insurance_agency_category_product_four = wp_get_attachment_image_src( $bosa_insurance_agency_departmentsfourID ,'bosa-insurance-agency-420-300');
 	if ( is_array( $bosa_insurance_agency_category_product_four ) ){
 		$bosa_insurance_agency_has_product_two = true;
   	 	$bosa_insurance_agency_category_products_four = $bosa_insurance_agency_category_product_four[0];
   	 	$bosa_insurance_agency_category_product_two_array['image_four'] ['ID'] = $bosa_insurance_agency_category_products_four;	 	
  	}
  	if ( !empty($bosa_insurance_agency_departmentsfour) ){
 		$bosa_insurance_agency_has_product_two = true;
   	 	$bosa_insurance_agency_category_product_two_array['image_four']['category'] = $bosa_insurance_agency_departmentsfour;	
  	}
}
if( !empty( $bosa_insurance_agency_departmentsfiveID ) || !empty( $bosa_insurance_agency_departmentsfive ) ){
	$bosa_insurance_agency_category_product_five = wp_get_attachment_image_src( $bosa_insurance_agency_departmentsfiveID ,'bosa-insurance-agency-420-300');
 	if ( is_array( $bosa_insurance_agency_category_product_five ) ){
 		$bosa_insurance_agency_has_product_two = true;
   	 	$bosa_insurance_agency_category_products_five = $bosa_insurance_agency_category_product_five[0];
   	 	$bosa_insurance_agency_category_product_two_array['image_five'] ['ID'] = $bosa_insurance_agency_category_products_five;	 	
  	}
  	if ( !empty( $bosa_insurance_agency_departmentsfive ) ){
 		$bosa_insurance_agency_has_product_two = true;
   	 	$bosa_insurance_agency_category_product_two_array['image_five']['category'] = $bosa_insurance_agency_departmentsfive;	
  	}
}
if( !empty( $bosa_insurance_agency_departmentssixID ) || !empty( $bosa_insurance_agency_departmentssix ) ){
	$bosa_insurance_agency_category_product_six = wp_get_attachment_image_src( $bosa_insurance_agency_departmentssixID ,'bosa-insurance-agency-420-300');
 	if ( is_array( $bosa_insurance_agency_category_product_six ) ){
 		$bosa_insurance_agency_has_product_three = true;
   	 	$bosa_insurance_agency_category_products_six = $bosa_insurance_agency_category_product_six[0];
   	 	$bosa_insurance_agency_category_product_three_array['image_six'] ['ID'] = $bosa_insurance_agency_category_products_six;	 	
  	}
  	if ( !empty( $bosa_insurance_agency_departmentssix ) ){
 		$bosa_insurance_agency_has_product_three = true;
   	 	$bosa_insurance_agency_category_product_three_array['image_six']['category'] = $bosa_insurance_agency_departmentssix;	
  	}
}
if( !empty( $bosa_insurance_agency_departmentssevenID ) || !empty( $bosa_insurance_agency_departmentsseven ) ){
	$bosa_insurance_agency_category_product_seven = wp_get_attachment_image_src( $bosa_insurance_agency_departmentssevenID ,'bosa-insurance-agency-420-300');
 	if ( is_array( $bosa_insurance_agency_category_product_seven ) ){
 		$bosa_insurance_agency_has_product_three = true;
   	 	$bosa_insurance_agency_category_products_seven = $bosa_insurance_agency_category_product_seven[0];
   	 	$bosa_insurance_agency_category_product_three_array['image_seven'] ['ID'] = $bosa_insurance_agency_category_products_seven;	 	
  	}
  	if ( !empty( $bosa_insurance_agency_departmentsseven ) ){
 		$bosa_insurance_agency_has_product_three = true;
   	 	$bosa_insurance_agency_category_product_three_array['image_seven']['category'] = $bosa_insurance_agency_departmentsseven;	
  	}
}
if( !empty( $bosa_insurance_agency_departmentseightID ) || !empty( $bosa_insurance_agency_departmentseight ) ){
	$bosa_insurance_agency_category_product_eight = wp_get_attachment_image_src( $bosa_insurance_agency_departmentseightID ,'bosa-insurance-agency-420-300');
 	if ( is_array( $bosa_insurance_agency_category_product_eight ) ){
 		$bosa_insurance_agency_has_product_three = true;
   	 	$bosa_insurance_agency_category_products_eight = $bosa_insurance_agency_category_product_eight[0];
   	 	$bosa_insurance_agency_category_product_three_array['image_eight'] ['ID'] = $bosa_insurance_agency_category_products_eight;	 	
  	}
  	if ( !empty( $bosa_insurance_agency_departmentseight ) ){
 		$bosa_insurance_agency_has_product_three = true;
   	 	$bosa_insurance_agency_category_product_three_array['image_eight']['category'] = $bosa_insurance_agency_departmentseight;	
  	}
}
if( !empty( $bosa_insurance_agency_departmentsnineID ) || !empty( $bosa_insurance_agency_departmentsnine ) ){
	$bosa_insurance_agency_category_product_nine = wp_get_attachment_image_src( $bosa_insurance_agency_departmentsnineID ,'bosa-insurance-agency-420-300');
 	if ( is_array( $bosa_insurance_agency_category_product_nine ) ){
 		$bosa_insurance_agency_has_product_three = true;
   	 	$bosa_insurance_agency_category_products_nine = $bosa_insurance_agency_category_product_nine[0];
   	 	$bosa_insurance_agency_category_product_three_array['image_nine'] ['ID'] = $bosa_insurance_agency_category_products_nine;	 	
  	}
  	if ( !empty( $bosa_insurance_agency_departmentsnine ) ){
 		$bosa_insurance_agency_has_product_three = true;
   	 	$bosa_insurance_agency_category_product_three_array['image_nine']['category'] = $bosa_insurance_agency_departmentsnine;	
  	}
}

$bosa_insurance_agency_product_cat = bosa_insurance_agency_get_post_categories();

if( !get_theme_mod( 'bosa_insurance_agency_disable_departments_section', true ) && ( $bosa_insurance_agency_has_product_one || $bosa_insurance_agency_has_product_two || $bosa_insurance_agency_has_product_three || get_theme_mod( 'bosa_insurance_agency_department_title_one' ) || get_theme_mod( 'bosa_insurance_agency_department_title_two' ) || get_theme_mod( 'bosa_insurance_agency_department_title_three' ) ) ){ ?>
	<section class="section-departments-area">
		<div class="row">
			<?php if( $bosa_insurance_agency_has_product_one || get_theme_mod( 'bosa_insurance_agency_department_title_one' ) ){ ?>
				<div class="col-md-12 col-lg-4">
					<div class="category-wraper">
						<?php if( get_theme_mod( 'bosa_insurance_agency_department_title_one' ) ){ ?>
							<div class="section-title-wrap">
								<h2 class="department-section-title">	
									<?php echo esc_html( get_theme_mod( 'bosa_insurance_agency_department_title_one' ) ); ?>
								</h2>
							</div>
						<?php } ?>
						<div class="content-wrap">
							<div class="row">
								<?php foreach( $bosa_insurance_agency_category_product_one_array as $bosa_insurance_agency_each_departmentsone ){ ?>
									<div class="col-sm-12">
										<article class="category-content-wrap">
											<?php 
											if ( isset( $bosa_insurance_agency_each_departmentsone['ID'] ) && !empty( $bosa_insurance_agency_each_departmentsone['ID'] ) ){
												$bosa_insurance_agency_cat_url = '';
												if( isset( $bosa_insurance_agency_each_departmentsone['category'] ) && !empty( $bosa_insurance_agency_each_departmentsone['category'] ) ) {
													$bosa_insurance_agency_cat_url = $bosa_insurance_agency_each_departmentsone['category'];
												}
											?>
												<figure class= "featured-image">
													<a href="<?php echo esc_url( get_category_link( $bosa_insurance_agency_cat_url ) ); ?>">
														<img src="<?php echo esc_url( $bosa_insurance_agency_each_departmentsone['ID'] ); ?>">
													</a>	
												</figure>
											<?php } ?>
											<?php if ( isset( $bosa_insurance_agency_each_departmentsone['category'] ) && !empty( $bosa_insurance_agency_each_departmentsone['category'] ) ){ ?>
												<h5 class="entry-title">
													<a href="<?php echo esc_url( get_category_link( $bosa_insurance_agency_each_departmentsone ['category'] ) ); ?>">
														<?php echo esc_html($bosa_insurance_agency_product_cat[$bosa_insurance_agency_each_departmentsone['category'] ] ); ?>
													</a>	
												</h5>
											<?php } ?>
										</article>	
									</div>
								<?php } ?>
							</div>
						</div>
					</div>
				</div>
			<?php } ?>
			<?php if( $bosa_insurance_agency_has_product_two || get_theme_mod( 'bosa_insurance_agency_department_title_two' ) ){ ?>
				<div class="col-md-6 col-lg-4">
					<div class="category-wraper">
						<?php if( get_theme_mod( 'bosa_insurance_agency_department_title_two' ) ){ ?>
							<div class="section-title-wrap">
								<h2 class="department-section-title">	
									<?php echo esc_html( get_theme_mod( 'bosa_insurance_agency_department_title_two' ) ); ?>
								</h2>
							</div>
						<?php } ?>
						<div class="content-wrap">
							<div class="row flex-row-container">
								<?php foreach( $bosa_insurance_agency_category_product_two_array as $bosa_insurance_agency_each_departmentstwo ){ ?>
									<div class="col-sm-6 px-lg-2 flex-col-container">
										<article class="category-content-wrap">
											<?php 
											if ( isset( $bosa_insurance_agency_each_departmentstwo['ID'] ) && !empty( $bosa_insurance_agency_each_departmentstwo['ID'] ) ){
												$bosa_insurance_agency_cat_url = '';
												if( isset( $bosa_insurance_agency_each_departmentstwo['category'] ) && !empty( $bosa_insurance_agency_each_departmentstwo['category'] ) ) {
													$bosa_insurance_agency_cat_url = $bosa_insurance_agency_each_departmentstwo['category'];
												}
											?>
												<figure class= "featured-image">
													<a href="<?php echo esc_url( get_category_link( $bosa_insurance_agency_cat_url ) ); ?>">
														<img src="<?php echo esc_url( $bosa_insurance_agency_each_departmentstwo['ID'] ); ?>">
													</a>	
												</figure>
											<?php } ?>
											<?php if ( isset( $bosa_insurance_agency_each_departmentstwo['category'] ) && !empty( $bosa_insurance_agency_each_departmentstwo['category'] ) ){ ?>
												<h5 class="entry-title">
													<a href="<?php echo esc_url( get_category_link( $bosa_insurance_agency_each_departmentstwo ['category'] ) ); ?>">
														<?php echo esc_html($bosa_insurance_agency_product_cat[$bosa_insurance_agency_each_departmentstwo['category'] ] ); ?>
													</a>	
												</h5>
											<?php } ?>
										</article>	
									</div>
								<?php } ?>
							</div>
						</div>
					</div>
				</div>
			<?php } ?>
			<?php if( $bosa_insurance_agency_has_product_three || get_theme_mod( 'bosa_insurance_agency_department_title_three' ) ){ ?>
				<div class="col-md-6 col-lg-4">
					<div class="category-wraper">
						<?php if( get_theme_mod( 'bosa_insurance_agency_department_title_three' ) ){ ?>
							<div class="section-title-wrap">
								<h2 class="department-section-title">	
									<?php echo esc_html( get_theme_mod( 'bosa_insurance_agency_department_title_three' ) ); ?>
								</h2>
							</div>
						<?php } ?>
						<div class="content-wrap">
							<div class="row flex-row-container">
								<?php foreach( $bosa_insurance_agency_category_product_three_array as $bosa_insurance_agency_each_departmentsthree ){ ?>
									<div class="col-sm-6 px-lg-2 flex-col-container">
										<article class="category-content-wrap">
											<?php 
											if ( isset( $bosa_insurance_agency_each_departmentsthree['ID'] ) && !empty( $bosa_insurance_agency_each_departmentsthree['ID'] ) ){
												$bosa_insurance_agency_cat_url = '';
												if( isset( $bosa_insurance_agency_each_departmentsthree['category'] ) && !empty( $bosa_insurance_agency_each_departmentsthree['category'] ) ) {
													$bosa_insurance_agency_cat_url = $bosa_insurance_agency_each_departmentsthree['category'];
												}
											?>
												<figure class= "featured-image">
													<a href="<?php echo esc_url( get_category_link( $bosa_insurance_agency_cat_url ) ); ?>">
														<img src="<?php echo esc_url( $bosa_insurance_agency_each_departmentsthree['ID'] ); ?>">
													</a>	
												</figure>
											<?php } ?>
											<?php if ( isset( $bosa_insurance_agency_each_departmentsthree['category'] ) && !empty( $bosa_insurance_agency_each_departmentsthree['category'] ) ){ ?>
												<h5 class="entry-title">
													<a href="<?php echo esc_url( get_category_link( $bosa_insurance_agency_each_departmentsthree ['category'] ) ); ?>">
														<?php echo esc_html($bosa_insurance_agency_product_cat[$bosa_insurance_agency_each_departmentsthree['category'] ] ); ?>
													</a>	
												</h5>
											<?php } ?>
										</article>	
									</div>
								<?php } ?>
							</div>
						</div>
					</div>
				</div>
			<?php } ?>
		</div>
	</section>
<?php }
