<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

$ethrik_logo = ethrik_get_option( 'theme_logo' );
$ethrik_logo_id = isset($ethrik_logo['id']) && !empty($ethrik_logo['id']) ? $ethrik_logo['id'] : '';
$ethrik_logo_url = isset( $ethrik_logo[ 'url' ] ) ? $ethrik_logo[ 'url' ] : '';
$ethrik_logo_alt = get_post_meta($ethrik_logo_id,'_wp_attachment_image_alt',true);

$ethrik_dark_logo = ethrik_get_option( 'theme_dark_logo' );
$ethrik_logo_dark_id = isset($ethrik_dark_logo['id']) && !empty($ethrik_dark_logo['id']) ? $ethrik_dark_logo['id'] : '';
$ethrik_logo_dark_url = isset( $ethrik_dark_logo[ 'url' ] ) ? $ethrik_dark_logo[ 'url' ] : '';
$ethrik_logo_dark_alt = get_post_meta($ethrik_logo_dark_id,'_wp_attachment_image_alt',true);

$ethrik_dark_mode_switcher = ethrik_get_option('dark_mode_enable', true);

$header_login_btn = ethrik_get_option('header_login_btn');
$header_create_nft_btn = ethrik_get_option('header_create_nft_btn');

$login_btn_text = ethrik_get_option('login_btn_text');
$login_btn_link = ethrik_get_option('login_btn_link');

$nft_btn_text = ethrik_get_option('nft_btn_text');
$create_nft_link = ethrik_get_option('create_nft_link');

$theme_header_sticky = ethrik_get_option('theme_header_sticky', true);

$different_mobile_menu = ethrik_get_option('different_mobile_menu');
$mobile_menu_socials = ethrik_get_option('mobile_menu_social');
$social_account_icon = ethrik_get_option('social_account_icon');
$social_account_link = ethrik_get_option('social_account_link');

?>

<header id="theme-header-one" class="theme_header__main header-style-one <?php if( $theme_header_sticky == true ) { echo "stick-top"; } else { echo "stick-disable"; } ?>">
	<div class="theme-header-area">
		<div class="container">
			<div class="row justify-content-between align-items-center <?php echo $different_mobile_menu ? 'responsive-mobile-menu' : ''; ?>">
				<div class="<?php echo $header_create_nft_btn ? "col-lg-1 col-md-2 col-sm-2" : "col-lg-2 col-md-2 col-sm-2"; ?>">
					<div class="logo theme-logo">
						<?php  
						if ( has_custom_logo() || !empty( $ethrik_logo_url ) ) {
							if( isset( $ethrik_logo['url'] ) && !empty( $ethrik_logo_url ) ) { 
								?>
									<a href="<?php echo esc_url( site_url('/')) ?>" class="logo">
										<img class="img-fluid" src="<?php echo esc_url( $ethrik_logo_url ); ?>" alt="<?php echo esc_attr( $ethrik_logo_alt  ) ?>">
									</a>
								<?php 
							} else {
								the_custom_logo();
							}

						} else {
							printf('<h1 class="text-logo"><a href="%1$s">%2$s</a></h1>',esc_url(site_url('/')),esc_html(get_bloginfo('name')));
						}
						?>
					</div>
					<?php if($ethrik_dark_mode_switcher == true) :?>
						<div class="logo dark-mode-logo">
							<?php  
								if (!empty( $ethrik_logo_dark_url ) ) {
									if( isset( $ethrik_dark_logo['url'] ) && !empty( $ethrik_logo_dark_url ) ) { 
										?>
										<a href="<?php echo esc_url( site_url('/')) ?>" class="logo">
											<img class="img-fluid" src="<?php echo esc_url( $ethrik_logo_dark_url ); ?>" alt="<?php echo esc_attr( $ethrik_logo_dark_alt  ) ?>">
										</a>
										<?php 
									} else {
											the_custom_logo();
									}
								}
							?>
						</div>
					<?php endif; ?>
				</div>
				
				<div class="<?php echo $header_create_nft_btn ? "col-lg-6 col-md-1 col-sm-1" : "col-lg-8 col-md-2 col-sm-1"; ?> nav-design-one">
					<div class="nav-menu-wrapper">
						<div class="container nav-wrapper-one">

						<?php if($different_mobile_menu == false) :?>
						<div class="ethrik-responsive-menu"></div>
						<?php endif; ?>

							<div class="mainmenu">
								<?php
									wp_nav_menu( array(
										'theme_location' => 'primary',
										'container' => 'nav',
										'container_class' => 'nav-main-wrap',
										'menu_class' => 'theme-main-menu',
										'menu_id'        => 'primary-menu',
									) );
								?>
							</div>
						</div>
					</div>	
				</div>
				
				<div class="<?php echo $header_create_nft_btn ? 'col-lg-5 col-md-9 col-sm-9' : 'col-lg-2 col-md-2 col-sm-9'; ?>">
					
					<div class="header-right-content <?php echo $different_mobile_menu ? 'diff-mobile-menu' : ''; ?> text-right">
					
						<div class="search-form-main">
							<form role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
								<input type="text" class="hsearch-input" value="<?php echo get_search_query(); ?>" name="s" placeholder="<?php esc_attr_e('Search','ethrik'); ?>" required />
								<button type="submit" id="searchsubmitt" class="hsearch-button"><i class="icofont-search"></i></button>
							</form>
						</div>
						
						<?php if($header_login_btn == true) :?>
						<div class="header-login-btn">
							<a href="<?php echo esc_url($login_btn_link); ?>" target="_blank"><?php echo esc_html($login_btn_text); ?></a>
						</div>
						<?php endif; ?>

						<?php if($header_create_nft_btn == true) :?>
						<div class="header-create-nft-btn">
							<a href="<?php echo esc_url($create_nft_link); ?>" target="_blank"><?php echo esc_html($nft_btn_text); ?></a>
						</div>
						<?php endif; ?>

						<?php if($ethrik_dark_mode_switcher == true) :?>
						<div class="mode-switcher">
							<i class="ifont mode-icon-change"></i>
						</div>
						<?php endif; ?>

						<?php if($different_mobile_menu == true) :?>
						<!-- Different Mobile Menu -->
						<div class="ethrik-diff-mobile-menu">
							<button class="btn" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasMobileMenu" aria-controls="offcanvasMobileMenu">
								<i class="fas fa-bars"></i>
							</button>
						</div>

						<!-- Offcanvas Mobile Menu -->
						 <div class="responsive-menu">
							<div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasMobileMenu" aria-labelledby="offcanvasMobileMenuLabel">
								<div class="offcanvas-header">
									<div class="logo theme-logo">
										<?php  
										if ( has_custom_logo() || !empty( $ethrik_logo_url ) ) {
											if( isset( $ethrik_logo['url'] ) && !empty( $ethrik_logo_url ) ) { 
												?>
													<a href="<?php echo esc_url( site_url('/')) ?>" class="logo">
														<img class="img-fluid" src="<?php echo esc_url( $ethrik_logo_url ); ?>" alt="<?php echo esc_attr( $ethrik_logo_alt  ) ?>">
													</a>
												<?php 
											} else {
												the_custom_logo();
											}

										} else {
											printf('<h1 class="text-logo"><a href="%1$s">%2$s</a></h1>',esc_url(site_url('/')),esc_html(get_bloginfo('name')));
										}
										?>
									</div>
									<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
								</div>
								<div class="offcanvas-body">
									<!-- Responsive Menu -->
									<?php
										wp_nav_menu( array(
											'theme_location' => 'mobile',
											'container' => 'div',
											'container_class' => 'responsive-nav',
											'menu_class' => 'main-responsive-menu',
											'menu_id'        => 'mobile-menu',
										) );
									?>
									<!-- Social Buttons Menu -->
									<?php if( $mobile_menu_socials ) : ?>
									<ul class="footer-social d-flex justify-content-start align-items-center">
										<?php foreach( $mobile_menu_socials as $mobile_menu_social ){ ?>
										<li>
											<a href="<?php echo $mobile_menu_social['social_account_link']['url']; ?>" target="_blank">
												<i class="<?php echo $mobile_menu_social['social_account_icon']; ?>"></i>
											</a>
										</li>
										<?php } ?>
									</ul>
									<?php endif; ?>
								</div>
							</div>
						</div>
						<?php endif; ?>

					</div>

				</div>
			</div>
		</div>
	</div>
</header>