<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }
$primary_has_menu = has_nav_menu( 'primary' );
$mobile_location  = has_nav_menu( 'mobile' ) ? 'mobile' : 'primary';
?>
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
  <meta charset="<?php bloginfo( 'charset' ); ?>">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
<a class="lt-skip-link" href="#main-content"><?php esc_html_e( 'Skip to content', 'law-temple-theme' ); ?></a>

<?php
$lt_block_header = '';
if ( 'pattern' === lt_theme_option( 'header_source', 'theme' ) && function_exists( 'lt_theme_render_synced_pattern' ) ) {
    $lt_block_header = lt_theme_render_synced_pattern( absint( lt_theme_option( 'header_pattern_id' ) ) );
}
?>

<?php if ( lt_theme_option( 'announcement' ) ) : ?>
  <div class="lt-announcement">
    <?php if ( lt_theme_option( 'announcement_url' ) ) : ?><a href="<?php echo esc_url( lt_theme_option( 'announcement_url' ) ); ?>"><?php endif; ?>
      <?php echo esc_html( lt_theme_option( 'announcement_text' ) ); ?>
    <?php if ( lt_theme_option( 'announcement_url' ) ) : ?></a><?php endif; ?>
  </div>
<?php endif; ?>

<?php if ( lt_theme_option( 'show_topbar' ) ) : ?>
  <div class="lt-topbar">
    <div class="lt-container">
      <span><?php echo esc_html( lt_theme_option( 'topbar_text' ) ); ?></span>
      <span>
        <?php echo esc_html( lt_theme_core_option( 'phone_primary' ) ); ?>
        <?php if ( lt_theme_core_option( 'general_email' ) ) : ?>
          <span aria-hidden="true"> · </span><a href="mailto:<?php echo esc_attr( antispambot( lt_theme_core_option( 'general_email' ) ) ); ?>"><?php echo esc_html( antispambot( lt_theme_core_option( 'general_email' ) ) ); ?></a>
        <?php endif; ?>
      </span>
    </div>
  </div>
<?php endif; ?>

<?php if ( $lt_block_header ) : ?>
  <div class="lt-block-template-part lt-block-template-part--header"><?php echo $lt_block_header; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php else : ?>
<header class="lt-site-header" data-site-header>
  <div class="lt-container lt-header-inner">
    <a class="lt-brand" href="<?php echo esc_url( home_url( '/' ) ); ?>" aria-label="<?php echo esc_attr( lt_theme_firm_name() ); ?>">
      <span class="lt-brand-logo lt-brand-logo--desktop"><?php echo lt_theme_logo( 'primary' ); ?></span>
      <span class="lt-brand-logo lt-brand-logo--mobile"><?php echo lt_theme_logo( 'mobile' ); ?></span>
    </a>

    <?php if ( $primary_has_menu ) : ?>
      <nav class="lt-nav" aria-label="<?php esc_attr_e( 'Primary navigation', 'law-temple-theme' ); ?>">
        <?php wp_nav_menu( lt_theme_primary_menu_args() ); ?>
      </nav>
    <?php endif; ?>

    <div class="lt-header-actions">
      <?php if ( lt_theme_option( 'show_search' ) ) : ?>
        <button class="lt-search-toggle" type="button" data-search-toggle aria-label="<?php esc_attr_e( 'Search', 'law-temple-theme' ); ?>">⌕</button>
      <?php endif; ?>
      <?php if ( lt_theme_option( 'header_cta_label' ) ) :
        $contact = get_page_by_path( 'contact' );
        $cta_url = lt_theme_option( 'header_cta_url' ) ?: ( $contact ? get_permalink( $contact ) : home_url( '/contact/' ) ); ?>
        <a class="lt-button lt-button--outline lt-header-cta" href="<?php echo esc_url( $cta_url ); ?>"><?php echo esc_html( lt_theme_option( 'header_cta_label' ) ); ?></a>
      <?php endif; ?>
      <?php if ( $primary_has_menu || has_nav_menu( 'mobile' ) ) : ?>
        <button class="lt-menu-toggle" type="button" data-menu-toggle aria-expanded="false" aria-controls="lt-mobile-navigation" aria-label="<?php esc_attr_e( 'Open menu', 'law-temple-theme' ); ?>"><span aria-hidden="true">☰</span></button>
      <?php endif; ?>
    </div>
  </div>

  <?php if ( $primary_has_menu || has_nav_menu( 'mobile' ) ) : ?>
    <nav id="lt-mobile-navigation" class="lt-mobile-nav" data-mobile-nav aria-label="<?php esc_attr_e( 'Mobile navigation', 'law-temple-theme' ); ?>">
      <?php wp_nav_menu( array( 'theme_location'=>$mobile_location, 'container'=>false, 'fallback_cb'=>false, 'depth'=>3 ) ); ?>
    </nav>
  <?php endif; ?>

  <?php if ( lt_theme_option( 'show_search' ) ) : ?>
    <div class="lt-search-panel" data-search-panel hidden>
      <div data-live-search>
        <?php get_search_form(); ?>
        <p class="screen-reader-text" aria-live="polite" data-search-status></p>
        <div class="lt-search-results" data-search-results hidden></div>
      </div>
    </div>
  <?php endif; ?>
</header>
<?php endif; ?>
