<?php
/**
 * Footer columns — About, Quick Links, Recent Posts, Contact (pro-style).
 *
 * @package ttsunsolar
 */

$about_title = ttsunsolar_mod( 'ttsunsolar_footer_about_title', __( 'About Us', 'ttsunsolar' ) );
$about_text  = ttsunsolar_mod(
	'ttsunsolar_footer_about_text',
	__( 'TTSun Solar designs, installs, and supports efficient solar energy systems for homes, businesses, and clean transportation.', 'ttsunsolar' )
);
$links_title   = ttsunsolar_mod( 'ttsunsolar_footer_links_title', __( 'Quick Links', 'ttsunsolar' ) );
$posts_title   = ttsunsolar_mod( 'ttsunsolar_footer_posts_title', __( 'Recent Posts', 'ttsunsolar' ) );
$contact_title = ttsunsolar_mod( 'ttsunsolar_footer_contact_title', __( 'Contact Info', 'ttsunsolar' ) );
$phone         = ttsunsolar_mod( 'ttsunsolar_phone', '11111111111' );
$email         = ttsunsolar_mod( 'ttsunsolar_email', 'info@example.com' );
$address       = ttsunsolar_mod( 'ttsunsolar_footer_address', '123 Lorem Ipsum Street, Dolor Sit Amet, 00000' );
$website       = ttsunsolar_mod( 'ttsunsolar_website', 'https://example.com' );
$socials       = ttsunsolar_get_social_links();
$recent_posts  = ttsunsolar_get_footer_posts( 2 );
?>
<footer class="site-footer">
	<div class="container footer-grid">
		<section class="footer-column footer-column--about">
			<?php if ( is_active_sidebar( 'footer-1' ) ) : ?>
				<?php dynamic_sidebar( 'footer-1' ); ?>
			<?php else : ?>
				<h2 class="footer-title"><?php echo esc_html( $about_title ); ?></h2>
				<p class="footer-about-text"><?php echo esc_html( $about_text ); ?></p>
			<?php endif; ?>
		</section>

		<nav class="footer-column footer-column--links" aria-label="<?php esc_attr_e( 'Footer navigation', 'ttsunsolar' ); ?>">
			<?php if ( is_active_sidebar( 'footer-2' ) ) : ?>
				<?php dynamic_sidebar( 'footer-2' ); ?>
			<?php else : ?>
				<h2 class="footer-title"><?php echo esc_html( $links_title ); ?></h2>
				<?php
				if ( has_nav_menu( 'footer' ) ) {
					wp_nav_menu(
						array(
							'theme_location' => 'footer',
							'container'      => false,
							'menu_class'     => 'footer-links',
							'depth'          => 2,
							'fallback_cb'    => false,
						)
					);
				} else {
					ttsunsolar_fallback_footer_menu();
				}
				?>
			<?php endif; ?>
		</nav>

		<section class="footer-column footer-column--posts">
			<?php if ( is_active_sidebar( 'footer-3' ) ) : ?>
				<?php dynamic_sidebar( 'footer-3' ); ?>
			<?php else : ?>
				<h2 class="footer-title"><?php echo esc_html( $posts_title ); ?></h2>
				<div class="footer-posts">
					<?php if ( ! empty( $recent_posts ) ) : ?>
						<?php foreach ( $recent_posts as $item ) : ?>
							<article class="footer-post">
								<?php if ( ! empty( $item['image'] ) ) : ?>
									<a href="<?php echo esc_url( $item['url'] ); ?>">
										<img src="<?php echo esc_url( $item['image'] ); ?>" alt="<?php echo esc_attr( $item['title'] ); ?>" />
									</a>
								<?php endif; ?>
								<div class="footer-post__body">
									<h3><a href="<?php echo esc_url( $item['url'] ); ?>"><?php echo esc_html( $item['title'] ); ?></a></h3>
									<p><?php echo esc_html( $item['excerpt'] ); ?></p>
								</div>
							</article>
						<?php endforeach; ?>
					<?php else : ?>
						<p><?php esc_html_e( 'No recent posts yet.', 'ttsunsolar' ); ?></p>
					<?php endif; ?>
				</div>
			<?php endif; ?>
		</section>

		<section class="footer-column footer-column--contact">
			<?php if ( is_active_sidebar( 'footer-4' ) ) : ?>
				<?php dynamic_sidebar( 'footer-4' ); ?>
			<?php else : ?>
				<h2 class="footer-title"><?php echo esc_html( $contact_title ); ?></h2>
				<ul class="footer-contact">
					<?php if ( $address ) : ?>
						<li class="footer-contact__address"><i class="fa-solid fa-location-dot" aria-hidden="true"></i><span><?php echo esc_html( $address ); ?></span></li>
					<?php endif; ?>
					<?php if ( $phone ) : ?>
						<li class="footer-contact__phone"><i class="fa-solid fa-phone" aria-hidden="true"></i><a href="<?php echo esc_url( ttsunsolar_tel_href( $phone ) ); ?>"><?php echo esc_html( $phone ); ?></a></li>
					<?php endif; ?>
					<?php if ( $email ) : ?>
						<li class="footer-contact__email"><i class="fa-solid fa-envelope" aria-hidden="true"></i><a href="<?php echo esc_url( 'mailto:' . antispambot( $email ) ); ?>"><?php echo esc_html( $email ); ?></a></li>
					<?php endif; ?>
					<?php if ( $website ) : ?>
						<li class="footer-contact__web"><i class="fa-solid fa-link" aria-hidden="true"></i><a href="<?php echo esc_url( $website ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $website ); ?></a></li>
					<?php endif; ?>
				</ul>
				<div class="social-links social-links--footer" aria-label="<?php esc_attr_e( 'Footer social links', 'ttsunsolar' ); ?>">
					<?php foreach ( $socials as $network => $url ) : ?>
						<?php if ( ! $url ) { continue; } ?>
						<a href="<?php echo esc_url( $url ); ?>" target="_blank" rel="noopener noreferrer" aria-label="<?php echo esc_attr( ucfirst( $network ) ); ?>">
							<i class="<?php echo esc_attr( ttsunsolar_social_icon_class( $network ) ); ?>" aria-hidden="true"></i>
						</a>
					<?php endforeach; ?>
				</div>
			<?php endif; ?>
		</section>
	</div>

	<?php get_template_part( 'solarpanels/footer/panel', 'copyright' ); ?>
</footer>
