<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$profile_id    = $args['profile_id'] ?? '';
$country_state = gigneo_post_meta( $profile_id, '_gigneo_pm_country_state' );
$city          = gigneo_post_meta( $profile_id, '_gigneo_pm_city' );
$area          = gigneo_post_meta( $profile_id, '_gigneo_pm_area' );
$zip_code      = gigneo_post_meta( $profile_id, '_gigneo_pm_zip_code' );
$address       = gigneo_post_meta( $profile_id, '_gigneo_pm_address' );

if ( empty( $country_state ) || empty( $zip_code ) || empty( $address ) ) {
	return;
}

$country_state_list = gigneo_countries_with_states( 'active' );
$country_state_name = $country_state_list[ $country_state ] ?? '';
$city_term          = ! empty( $city ) ? get_term_by( 'slug', $city, 'gigneo_city' ) : '';
$city_name          = ( $city_term && ! is_wp_error( $city_term ) ) ? $city_term->name : '';
?>

<div id="gn-address" class="gn-section gn-locations-section">
	<div class="gn-head">
		<h3 class="gn-title"><?php esc_html_e( 'Address & location', 'gigneo' ); ?></h3>
	</div>
	<div class="gn-body gn-locations">
		<div class="gn-location">
			<span class="gn-icon">
				<i class="hi hi-map-pin" aria-hidden="true"></i>
			</span>
			<div class="gn-info">
				<h6 class="gn-country-state">
					<?php echo esc_html( implode( ', ', array_filter( array( $city_name, $country_state_name ) ) ) ); ?>
				</h6>
				<p class="gn-address">
					<?php
					$address_parts = array_filter( array( $area, $zip_code, $address ) );
					echo esc_html( implode( ', ', $address_parts ) );
					?>
				</p>
			</div>
		</div>
	</div>
</div>
