<?php
/**
 * Footer Template
 *
 * @package Peblog
 */
?>
<!-- footer start -->
<footer id="footer">
	<div class="footer-container">
		<div class="footer-box">
			<div class="footer-logo">
				<?php
				// Footer logo - light mode
				if ( has_custom_logo() ) {
					// WordPress custom logo exists
					$custom_logo_id  = get_theme_mod( 'custom_logo' );
					$custom_logo_url = wp_get_attachment_image_url( $custom_logo_id, 'full' );
					if ( $custom_logo_url ) {
						echo '<a href="' . esc_url( home_url( '/' ) ) . '" class="footer-logo-light" rel="home">';
						echo '<img src="' . esc_url( $custom_logo_url ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '" class="custom-logo" />';
						echo '</a>';
					}
				} else {
					// Fallback to theme customizer logo
					$custom_logo = get_theme_mod( 'peblog_logo', '' );
					if ( $custom_logo ) {
						echo '<a href="' . esc_url( home_url( '/' ) ) . '" class="footer-logo-light" rel="home">';
						echo '<img src="' . esc_url( $custom_logo ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '" />';
						echo '</a>';
					} else {
						echo '<a href="' . esc_url( home_url( '/' ) ) . '" class="footer-logo-light" rel="home">';
						echo '<span class="site-logo-text">' . esc_html( get_bloginfo( 'name', 'display' ) ) . '</span>';
						echo '</a>';
					}
				}

				// Footer logo - dark mode
				$custom_logo_white = get_theme_mod( 'peblog_logo_white', '' );
				if ( $custom_logo_white ) {
					// Dark mode logo from theme customizer
					echo '<a href="' . esc_url( home_url( '/' ) ) . '" class="footer-logo-dark" rel="home">';
					echo '<img src="' . esc_url( $custom_logo_white ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '" />';
					echo '</a>';
				} elseif ( has_custom_logo() ) {
					// If WordPress logo exists but no dark logo, use same logo
					$custom_logo_id  = get_theme_mod( 'custom_logo' );
					$custom_logo_url = wp_get_attachment_image_url( $custom_logo_id, 'full' );
					if ( $custom_logo_url ) {
						echo '<a href="' . esc_url( home_url( '/' ) ) . '" class="footer-logo-dark" rel="home">';
						echo '<img src="' . esc_url( $custom_logo_url ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '" class="custom-logo" />';
						echo '</a>';
					}
				} else {
					// Fallback: use light logo for dark mode if no dark logo set
					$custom_logo = get_theme_mod( 'peblog_logo', '' );
					if ( $custom_logo ) {
						echo '<a href="' . esc_url( home_url( '/' ) ) . '" class="footer-logo-dark" rel="home">';
						echo '<img src="' . esc_url( $custom_logo ) . '" alt="' . esc_attr( get_bloginfo( 'name' ) ) . '" />';
						echo '</a>';
					} else {
						echo '<a href="' . esc_url( home_url( '/' ) ) . '" class="footer-logo-dark" rel="home">';
						echo '<span class="site-logo-text">' . esc_html( get_bloginfo( 'name', 'display' ) ) . '</span>';
						echo '</a>';
					}
				}
				?>
			</div>
			<div class="footer-text">
				<p>
				<?php
				$description = get_bloginfo( 'description', 'display' );
				if ( $description ) {
					echo esc_html( $description );
				} else {
					esc_html_e( 'Peblog', 'peblog' );
				}
				?>
				</p>
			</div>
		</div>
		
		<div class="footer-box">
			<div class="footer-title">
				<h3><?php esc_html_e( 'Follow My Socials', 'peblog' ); ?></h3>
			</div>
			<div class="social-links">
				<ul class="footer-social-links">
					<?php
					$social_links = array(
						'instagram' => get_theme_mod( 'peblog_instagram_url', '' ),
						'twitter'   => get_theme_mod( 'peblog_twitter_url', '' ),
						'linkedin'  => get_theme_mod( 'peblog_linkedin_url', '' ),
						'github'    => get_theme_mod( 'peblog_github_url', '' ),
						'pinterest' => get_theme_mod( 'peblog_pinterest_url', '' ),
						'telegram'  => get_theme_mod( 'peblog_telegram_url', '' ),
						'youtube'   => get_theme_mod( 'peblog_youtube_url', '' ),
						'facebook'  => get_theme_mod( 'peblog_facebook_url', '' ),
						'dribbble'  => get_theme_mod( 'peblog_dribbble_url', '' ),
						'behance'   => get_theme_mod( 'peblog_behance_url', '' ),
					);

					foreach ( $social_links as $platform => $url ) {
						if ( ! empty( $url ) ) {
							$icon_path   = get_template_directory_uri() . '/assets/images/icon/' . $platform . '.svg';
							$icon_exists = file_exists( get_template_directory() . '/assets/images/icon/' . $platform . '.svg' );
							if ( $icon_exists ) {
								echo '<li class="' . esc_attr( $platform ) . '">';
								echo '<a href="' . esc_url( $url ) . '" target="_blank" rel="noopener">';
								echo '<img src="' . esc_url( $icon_path ) . '" alt="' . esc_attr( ucfirst( $platform ) ) . '" />';
								echo '</a>';
								echo '</li>';
							}
						}
					}
					?>
				</ul>
			</div>
		</div>
		
		<div class="footer-box">
			<div class="footer-title">
				<h3><?php echo esc_html( get_theme_mod( 'peblog_newsletter_title', __( 'Join Our Newsletter', 'peblog' ) ) ); ?></h3>
			</div>
			<div class="newsletter-form">
				<?php
				$newsletter_shortcode = get_theme_mod( 'peblog_newsletter_shortcode', '' );
				if ( ! empty( $newsletter_shortcode ) ) {
					// Show shortcode if provided
					echo do_shortcode( $newsletter_shortcode );
				} else {
					// Demo form for visual preview
					?>
					<form>
						<input type="email" placeholder="<?php esc_attr_e( 'Enter your email', 'peblog' ); ?>" />
						<input type="submit" value="<?php esc_attr_e( 'Subscribe', 'peblog' ); ?>" />
					</form>
					<?php
				}
				?>
			</div>
		</div>
	</div>
	
	<div class="copyright">
		<span>
		<?php
		/* translators: 1: Year, 2: Site name */
		printf( esc_html__( 'Copyright © %1$s %2$s. All Rights Reserved.', 'peblog' ), esc_html( gmdate( 'Y' ) ), esc_html( get_bloginfo( 'name' ) ) );
		?>
		</span>
	</div>
</footer>
<!-- footer end -->

<?php wp_footer(); ?>
</body>
</html>
