<?php
/**
* Functions & definations for theme header
*
*
*/
add_action( 'portfolio_one_logo' , 'portfolio_one_logo', 10 );
if( ! function_exists('portfolio_one_logo')):
	function portfolio_one_logo(){
		?>
		<div class="site-branding">
			<?php
			the_custom_logo();
			portfolio_one_dark_logo();
			if ( is_front_page() && is_home() ) :
				?>
				<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
				<?php
			else :
				?>
				<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
				<?php
			endif;
			$portfolio_one_description = get_bloginfo( 'description', 'display' );
			if ( $portfolio_one_description || is_customize_preview() ) :
				?>
				<p class="site-description"><?php echo esc_html($portfolio_one_description); ?></p>
			<?php endif; ?>
		</div><!-- .site-branding -->
		<?php 
	}
endif;


function portfolio_one_dark_logo(){
		$default 				= portfolio_one_customizer_defaults();
		$cww_dark_mode_enable 	= get_theme_mod('cww_dark_mode_enable', $default['cww_dark_mode_enable']);
		$cww_logo_dark 			= get_theme_mod('cww_logo_dark');

		if( $cww_dark_mode_enable && $cww_logo_dark ){ ?>
			<a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="cww-dark-logo">
				<img src="<?php echo esc_url($cww_logo_dark)?>">
			</a>
		<?php }
}


add_action('portfolio_one_nav','portfolio_one_nav');
if( ! function_exists('portfolio_one_nav')):
	function portfolio_one_nav(){

		$default 				= portfolio_one_customizer_defaults();

		?>
		<header id="masthead" class="site-header">
			<div class="container cww-flex">
				<?php 
					do_action('portfolio_one_logo');
					
					
				 ?>
				<div class="menu-wrapp">
					<?php do_action('portfolio_one_mobile_menu'); ?>
					<div class="cww-menu-outer-wrapp cww-flex">
						<nav id="site-navigation" class="main-navigation">
							
							<?php
							wp_nav_menu(
								array(
									'theme_location' 	=> 'menu-1',
									'menu_id'        	=> 'primary-menu',
									'menu_class' 	 	=> 'cww-main-nav',
									'container_class' 	=> 'cww-nav-container'
								)
							);
							?>
						</nav><!-- #site-navigation -->
						<?php 
							do_action('portfolio_one_header_button');
						?>
						<div class="menu-last-focus-item"></div>
					</div>
				</div>
				<?php
				do_action('portfolio_one_header_text');
				?>

			</div>
		</header><!-- #masthead -->
		<?php 
	}
endif;


add_action('portfolio_one_header_button','portfolio_one_header_button');
if( ! function_exists('portfolio_one_header_button')):
	function portfolio_one_header_button(){

		$default 					= portfolio_one_customizer_defaults();
		$cww_header_cta_enable 		= get_theme_mod('cww_header_cta_enable', $default['cww_header_cta_enable'] );
		$cww_header_cta_text 		= get_theme_mod('cww_header_cta_text', $default['cww_header_cta_text'] );
		$cww_header_cta_url 		= get_theme_mod('cww_header_cta_url', $default['cww_header_cta_url']);
		$cww_header_cta_new_tab 	= get_theme_mod('cww_header_cta_new_tab', $default['cww_header_cta_new_tab']);

		if( empty($cww_header_cta_enable)){
			return;
		}
		
		$cww_header_cta_new_tab = ($cww_header_cta_new_tab == 1 ) ? "_blank" : '_self';

		$header_cta_layout = apply_filters(
			'portfolio_one_header_cta_layout',
			'layout-one'
		);

		?>
		<div class="header-cta-wrapp <?php echo esc_attr( $header_cta_layout ); ?>">
			<a href="<?php echo esc_url($cww_header_cta_url);?>" target="<?php echo esc_attr($cww_header_cta_new_tab);?>">
				<span>
					<?php echo esc_html($cww_header_cta_text); ?>
				</span>
			</a>
		</div>
		<?php 
	}
endif;


/**
* Mobile menu
*
*/
add_action('portfolio_one_mobile_menu','portfolio_one_mobile_menu');
if(! function_exists('portfolio_one_mobile_menu')):
	function portfolio_one_mobile_menu(){
		?>
		<button class="button is-text" id="mob-toggle-menu-button">
            <span class="button-inner-wrapper">
                <span class="icon menu-icon"></span>
			</span>
        </button>
		<?php 
	}
endif;