<?php
/**
 * Site header.
 *
 * @package HaPantheon
 */

$direction      = get_theme_mod( 'hapantheon_direction', 'rtl' );
$default_scheme = get_theme_mod( 'hapantheon_default_scheme', 'system' );
$custom_logo_id = get_theme_mod( 'custom_logo' );
$site_title     = get_bloginfo( 'name' );
$site_tagline   = get_bloginfo( 'description' );
?><!doctype html>
<html lang="<?php echo esc_attr( get_bloginfo( 'language' ) ); ?>" dir="<?php echo esc_attr( $direction ); ?>">
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="theme-color" content="#0E5F66">
	<script>
		(function () {
			var saved = null;
			try { saved = localStorage.getItem('pantheon-theme'); } catch (e) {}
			var fallback = <?php echo wp_json_encode( $default_scheme ); ?>;
			var scheme = saved || (fallback === 'system'
				? ((window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light')
				: fallback);
			document.documentElement.setAttribute('data-theme', scheme);
		}());
	</script>
	<?php wp_head(); ?>
</head>
<body <?php body_class(); ?> dir="<?php echo esc_attr( $direction ); ?>">
<?php wp_body_open(); ?>
<a class="skip-link screen-reader-text" href="#primary"><?php esc_html_e( 'דילוג לתוכן', 'hapantheon' ); ?></a>
<?php if ( is_singular( 'post' ) ) : ?>
	<div class="progress" aria-hidden="true"></div>
<?php endif; ?>
<header class="nav solid" id="nav">
	<div class="wrap nav-in">
		<a class="brand" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
			<?php if ( $custom_logo_id ) : ?>
				<?php
				echo wp_get_attachment_image(
					$custom_logo_id,
					'full',
					false,
					array(
						'class' => 'custom-logo',
						'alt'   => $site_title,
					)
				);
				?>
			<?php else : ?>
				<?php echo hapantheon_icon( 'temple', 'mark' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
			<?php endif; ?>
			<span>
				<?php echo esc_html( $site_title ); ?>
				<?php if ( $site_tagline ) : ?>
					<small class="en"><?php echo esc_html( $site_tagline ); ?></small>
				<?php endif; ?>
			</span>
		</a>

		<nav class="primary-navigation" aria-label="<?php esc_attr_e( 'ניווט ראשי', 'hapantheon' ); ?>">
			<?php
			wp_nav_menu(
				array(
					'theme_location' => 'primary',
					'container'      => false,
					'menu_class'     => 'links',
					'menu_id'        => 'primary-menu',
					'fallback_cb'    => 'hapantheon_primary_menu_fallback',
					'depth'          => 2,
				)
			);
			?>
		</nav>

		<button class="search-btn" type="button" aria-label="<?php esc_attr_e( 'חיפוש בארכיון', 'hapantheon' ); ?>" aria-haspopup="dialog">
			<?php echo hapantheon_icon( 'search' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
		</button>
		<button class="tgl" type="button" aria-label="<?php esc_attr_e( 'החלפת ערכת צבעים', 'hapantheon' ); ?>" onclick="toggleTheme()">
			<?php echo hapantheon_icon( 'sun', 'sun' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
			<?php echo hapantheon_icon( 'moon', 'moon' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
		</button>
		<button class="burger" type="button" aria-label="<?php esc_attr_e( 'פתיחת תפריט', 'hapantheon' ); ?>" aria-haspopup="dialog">
			<?php echo hapantheon_icon( 'menu' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
		</button>
	</div>
</header>
<main id="primary" class="site-main">
