<?php
/**
 * Site header markup — topbar + navbar (pro-style layout).
 *
 * @package ttsunsolar
 */

$phone     = ttsunsolar_mod( 'ttsunsolar_phone', '11111111111' );
$email     = ttsunsolar_mod( 'ttsunsolar_email', 'info@example.com' );
$address   = ttsunsolar_mod( 'ttsunsolar_address', '123 Lorem Ipsum Street' );
$socials   = ttsunsolar_get_social_links();
$site_name = ttsunsolar_get_site_name();
$tagline   = ttsunsolar_get_site_tagline();
$has_logo  = has_custom_logo();
$show_tagline_with_logo = (bool) get_theme_mod( 'ttsunsolar_show_tagline_with_logo', true );
$is_preview             = is_customize_preview();

// Title is for text branding when no logo; keep in Customizer DOM for live edit.
$show_title_visible   = ! $has_logo;
$show_tagline_visible = (bool) $tagline && ( ! $has_logo || $show_tagline_with_logo );
$render_brand_text    = $show_title_visible || $show_tagline_visible || $is_preview;

$brand_class = 'brand';
if ( $has_logo && $show_tagline_visible ) {
	$brand_class .= ' brand--logo-tagline';
}

$brand_link_class = 'brand__link';
if ( $has_logo && ! $show_tagline_visible ) {
	$brand_link_class .= ' brand__link--with-logo';
} elseif ( $has_logo && $show_tagline_visible ) {
	$brand_link_class .= ' brand__link--under-logo';
}
?>
<header class="site-header">
	<div class="topbar">
		<div class="container topbar__inner">
			<div class="social-links" aria-label="<?php esc_attr_e( '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>
			<address class="contact-strip">
				<?php if ( $phone ) : ?>
					<a class="contact-strip__phone" href="<?php echo esc_url( ttsunsolar_tel_href( $phone ) ); ?>">
						<i class="fa-solid fa-phone" aria-hidden="true"></i> <?php echo esc_html( $phone ); ?>
					</a>
				<?php endif; ?>
				<?php if ( $email ) : ?>
					<a class="contact-strip__email" href="<?php echo esc_url( 'mailto:' . antispambot( $email ) ); ?>">
						<i class="fa-solid fa-envelope" aria-hidden="true"></i> <?php echo esc_html( $email ); ?>
					</a>
				<?php endif; ?>
				<?php if ( $address ) : ?>
					<span class="contact-strip__address"><i class="fa-solid fa-location-dot" aria-hidden="true"></i> <?php echo esc_html( $address ); ?></span>
				<?php endif; ?>
			</address>
		</div>
	</div>

	<div class="navbar">
		<div class="container navbar__inner">
			<div class="<?php echo esc_attr( $brand_class ); ?>">
				<?php if ( $has_logo ) : ?>
					<?php the_custom_logo(); ?>
				<?php endif; ?>
				<?php if ( $render_brand_text ) : ?>
					<a class="<?php echo esc_attr( $brand_link_class ); ?>" href="<?php echo esc_url( home_url( '/' ) ); ?>">
						<span class="brand__text">
							<?php if ( $show_title_visible || $is_preview ) : ?>
								<span class="brand__name<?php echo $has_logo ? ' screen-reader-text' : ''; ?>" data-default="<?php echo esc_attr( ttsunsolar_default_site_name() ); ?>"><?php echo esc_html( $site_name ); ?></span>
							<?php endif; ?>
							<?php if ( $show_tagline_visible || ( $is_preview && $tagline ) ) : ?>
								<span class="brand__tagline<?php echo ( $has_logo && ! $show_tagline_visible ) ? ' screen-reader-text' : ''; ?>" data-default="<?php echo esc_attr( ttsunsolar_default_site_tagline() ); ?>"><?php echo esc_html( $tagline ); ?></span>
							<?php endif; ?>
						</span>
					</a>
				<?php endif; ?>
			</div>

			<div class="navbar__nav-shell">
				<button type="button" class="solar-nav-toggle" aria-expanded="false" aria-controls="main-navigation">
					<span class="solar-nav-toggle-icon" aria-hidden="true"><span></span><span></span><span></span></span>
					<span class="screen-reader-text"><?php esc_html_e( 'Menu', 'ttsunsolar' ); ?></span>
				</button>

				<nav class="main-nav" id="main-navigation" aria-label="<?php esc_attr_e( 'Main navigation', 'ttsunsolar' ); ?>">
					<div class="solar-nav-drawer-head">
						<span class="solar-nav-drawer-title"><?php esc_html_e( 'Menu', 'ttsunsolar' ); ?></span>
						<button type="button" class="solar-nav-drawer-close" aria-label="<?php esc_attr_e( 'Close menu', 'ttsunsolar' ); ?>">&times;</button>
					</div>
					<?php
					wp_nav_menu(
						array(
							'theme_location' => 'primary',
							'container'      => false,
							'menu_class'     => 'main-nav__list menu',
							'fallback_cb'    => 'ttsunsolar_fallback_menu',
						)
					);
					?>
				</nav>
			</div>
		</div>
	</div>
</header>
<div class="solar-nav-overlay" aria-hidden="true"></div>
