<?php
declare(strict_types=1);

/**
 * Header Inner — Logo, Navigation, CTA, SNS icons.
 *
 * @package WTE_Business_Card
 * @since   1.0.0
 */

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

$wte_logo_url       = get_theme_mod( 'wte_site_logo', '' );
$wte_tagline_show   = get_theme_mod( 'wte_site_tagline_display', true );
$wte_nav_display    = get_theme_mod( 'wte_nav_display', true );
$wte_cta_display    = get_theme_mod( 'wte_header_cta_display', true );
$wte_cta_text       = get_theme_mod( 'wte_header_cta_text', __( 'お問い合わせ', 'wte_' ) );
$wte_sns_in_header  = get_theme_mod( 'wte_sns_display_header', false );

// Contact page URL.
$wte_contact_pages = get_pages( [
	'meta_key'   => '_wte_is_contact_page',
	'meta_value' => '1',
	'number'     => 1,
] );
$wte_contact_url = ! empty( $wte_contact_pages ) ? get_permalink( $wte_contact_pages[0] ) : '#wte-contact-cta';
?>
<div class="wte-container">
	<div class="wte-header__inner">
		<!-- Site Branding -->
		<div class="wte-header__brand">
			<a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="wte-header__logo-link" aria-label="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>">
				<?php if ( $wte_logo_url ) : ?>
					<img
						src="<?php echo esc_url( $wte_logo_url ); ?>"
						alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>"
						class="wte-header__logo"
						width="200"
						height="60"
					>
				<?php else : ?>
					<span class="wte-header__site-title"><?php bloginfo( 'name' ); ?></span>
				<?php endif; ?>
			</a>
			<?php if ( $wte_tagline_show && get_bloginfo( 'description' ) ) : ?>
				<p class="wte-header__tagline"><?php bloginfo( 'description' ); ?></p>
			<?php endif; ?>
		</div>

		<!-- Navigation -->
		<div class="wte-header__actions">
			<?php if ( $wte_nav_display && has_nav_menu( 'primary' ) ) : ?>
				<nav class="wte-nav" role="navigation" aria-label="<?php esc_attr_e( 'メインナビゲーション', 'wte_' ); ?>">
					<?php
					wp_nav_menu( [
						'theme_location' => 'primary',
						'container'      => false,
						'menu_class'     => 'wte-nav__list',
						'depth'          => 1,
						'fallback_cb'    => false,
					] );
					?>
				</nav>
			<?php endif; ?>

			<?php if ( $wte_sns_in_header && function_exists( 'wte_render_sns_icons' ) ) : ?>
				<?php wte_render_sns_icons( 'header' ); ?>
			<?php endif; ?>

			<?php if ( $wte_cta_display ) : ?>
				<a href="<?php echo esc_url( $wte_contact_url ); ?>" class="wte-btn wte-btn--primary wte-btn--sm wte-header__cta">
					<?php echo esc_html( $wte_cta_text ); ?>
				</a>
			<?php endif; ?>

			<!-- Mobile Menu Toggle -->
			<button class="wte-header__menu-toggle" aria-label="<?php esc_attr_e( 'メニューを開く', 'wte_' ); ?>" aria-expanded="false">
				<span class="wte-hamburger">
					<span class="wte-hamburger__line"></span>
					<span class="wte-hamburger__line"></span>
					<span class="wte-hamburger__line"></span>
				</span>
			</button>
		</div>
	</div>
</div>

<!-- Mobile Navigation Drawer -->
<div class="wte-mobile-nav" id="wte-mobile-nav" aria-hidden="true">
	<div class="wte-mobile-nav__inner">
		<?php if ( has_nav_menu( 'primary' ) ) : ?>
			<nav role="navigation" aria-label="<?php esc_attr_e( 'モバイルナビゲーション', 'wte_' ); ?>">
				<?php
				wp_nav_menu( [
					'theme_location' => 'primary',
					'container'      => false,
					'menu_class'     => 'wte-mobile-nav__list',
					'depth'          => 1,
					'fallback_cb'    => false,
				] );
				?>
			</nav>
		<?php endif; ?>

		<?php if ( $wte_cta_display ) : ?>
			<a href="<?php echo esc_url( $wte_contact_url ); ?>" class="wte-btn wte-btn--primary wte-btn--full">
				<?php echo esc_html( $wte_cta_text ); ?>
			</a>
		<?php endif; ?>

		<?php if ( $wte_sns_in_header && function_exists( 'wte_render_sns_icons' ) ) : ?>
			<?php wte_render_sns_icons( 'header' ); ?>
		<?php endif; ?>
	</div>
</div>
