<?php
/**
 * Site title (mobile header content) template
 *
 * @package Multi
 */

/**
 * Site-title settings
 */
$logo_position = get_theme_mod( 'multi_header_mobile_logo_position', MULTIMAGAZINE_HEADER_MOBILE_LOGO_POSITION );
$menu_position = get_theme_mod( 'multi_header_mobile_menu_position', MULTIMAGAZINE_HEADER_MOBILE_MENU_POSITION );
$cart_position = class_exists( 'WooCommerce' ) ? get_theme_mod( 'multi_header_mobile_cart_position', MULTIMAGAZINE_HEADER_MOBILE_CART_POSITION ) : 'off';

$logo_position_desktop = get_theme_mod( 'multi_header_logo_position', MULTIMAGAZINE_HEADER_LOGO_POSITION );
$menu_position_desktop = get_theme_mod( 'multi_mainmenu_position', MULTIMAGAZINE_MAINMENU_POSITION );
$cart_position_desktop = class_exists( 'WooCommerce' ) ? get_theme_mod( 'multi_cart_in_menu', MULTIMAGAZINE_CART_IN_MENU ) : 'off';

$menu_animation_follow = get_theme_mod( 'multi_header_follow_mouse_mode', MULTIMAGAZINE_HEADER_FOLLOW_MOUSE_MODE );

switch ( true ) {
	case false !== strpos( $logo_position_desktop, 'left' ):
		$logo_position_desktop = 'left';
		break;
	case false !== strpos( $logo_position_desktop, 'right' ):
		$logo_position_desktop = 'right';
		break;
	case false !== strpos( $logo_position_desktop, 'center' ):
		$logo_position_desktop = 'center';
		break;
}
switch ( true ) {
	case false !== strpos( $menu_position_desktop, 'left' ):
		$menu_position_desktop = 'left';
		break;
	case false !== strpos( $menu_position_desktop, 'right' ):
		$menu_position_desktop = 'right';
		break;
}
switch ( true ) {
	case false !== strpos( $cart_position_desktop, 'left' ):
		$cart_position_desktop = 'left';
		break;
	case false !== strpos( $cart_position_desktop, 'right' ):
		$cart_position_desktop = 'right';
		break;
}

$positions_match = $logo_position === $logo_position_desktop && $menu_position === $menu_position_desktop && $cart_position === $cart_position_desktop;

$show_logo                = ! empty( $logo_position ) && display_header_text();
$show_cart                = 'off' !== $cart_position;
$menu_cart_position_equal = $menu_position === $cart_position;
$links_position_left      = ( $menu_cart_position_equal || ! $show_cart ) && 'left' === $menu_position;
$links_position_right     = ( $menu_cart_position_equal || ! $show_cart ) && 'right' === $menu_position;

$site_title_classes = array( 'site-title' );

if ( ! $positions_match ) {
	$site_title_classes[] = 'mobile';
}

if ( ! display_header_text() ) {
	$site_title_classes[] = 'no-logo';
}
if ( 'center' === $logo_position ) {
	$site_title_classes[] = 'logo-pos-center';

	if ( $links_position_left ) {
		$site_title_classes[] = 'links-left';
	} elseif ( $links_position_right ) {
		$site_title_classes[] = 'links-right';
	}
}
if ( $show_cart ) {
	$site_title_classes[] = 'cart-in-menu';
}

if ( $links_position_left && 'left' === $logo_position ) {
	$site_title_classes[] = 'align-content-left';
} elseif ( $links_position_right && 'right' === $logo_position ) {
	$site_title_classes[] = 'align-content-right';
}

?>

<div class="<?php echo esc_attr( implode( ' ', $site_title_classes ) ); ?>">
<?php

if ( $links_position_left ) {
	?>
	<div class="title-links">
	<?php
	get_template_part( 'template-parts/header-menu-toggle' );
	if ( $show_cart ) {
		get_template_part( 'template-parts/header-cart-link' );
	}
	?>
	</div>
	<?php
} elseif ( 'left' === $menu_position ) {
	get_template_part( 'template-parts/header-menu-toggle' );
} elseif ( 'left' === $cart_position ) {
	get_template_part( 'template-parts/header-cart-link' );
}


if ( $show_logo ) {
	get_template_part( 'template-parts/logo' );
}

if ( $links_position_right ) {
	?>
	<div class="title-links">
	<?php
	if ( $show_cart ) {
		get_template_part( 'template-parts/header-cart-link' );
	}
	get_template_part( 'template-parts/header-menu-toggle' );
	?>
	</div>
	<?php
} elseif ( 'right' === $menu_position ) {
	get_template_part( 'template-parts/header-menu-toggle' );
} elseif ( 'right' === $cart_position ) {
	get_template_part( 'template-parts/header-cart-link' );
}
?>
</div>
<?php
if ( ! $positions_match && get_theme_mod( 'multi_show_menus', MULTIMAGAZINE_SHOW_MENUS ) !== 'show-menus' ) :
	$show_logo                = ! empty( $logo_position_desktop ) && display_header_text();
	$show_cart                = 'off' !== $cart_position_desktop;
	$menu_cart_position_equal = $menu_position_desktop === $cart_position_desktop;
	$links_position_left      = ( $menu_cart_position_equal || ! $show_cart ) && 'left' === $menu_position_desktop;
	$links_position_right     = ( $menu_cart_position_equal || ! $show_cart ) && 'right' === $menu_position_desktop;

	$site_title_classes = array( 'site-title', 'menu-link-animations' );

	if ( ! $positions_match ) {
		$site_title_classes[] = 'desktop';
	}

	if ( ! display_header_text() ) {
		$site_title_classes[] = 'no-logo';
	}
	if ( 'center' === $logo_position_desktop ) {
		$site_title_classes[] = 'logo-pos-center';

		if ( $links_position_left ) {
			$site_title_classes[] = 'links-left';
		} elseif ( $links_position_right ) {
			$site_title_classes[] = 'links-right';
		}
	}
	if ( $show_cart ) {
		$site_title_classes[] = 'cart-in-menu';
	}

	if ( $links_position_left && 'left' === $logo_position_desktop ) {
		$site_title_classes[] = 'align-content-left';
	} elseif ( $links_position_right && 'right' === $logo_position_desktop ) {
		$site_title_classes[] = 'align-content-right';
	}
	?>

	<div class="<?php echo esc_attr( implode( ' ', $site_title_classes ) ); ?>">
	<?php

	if ( $links_position_left ) {
		?>
		<div class="title-links">
		<?php
		get_template_part( 'template-parts/header-menu-toggle' );
		if ( $show_cart ) {
			get_template_part( 'template-parts/header-cart-link' );
		}
		?>
		</div>
		<?php
	} elseif ( 'left' === $menu_position_desktop ) {
		get_template_part( 'template-parts/header-menu-toggle' );
	} elseif ( 'left' === $cart_position_desktop ) {
		get_template_part( 'template-parts/header-cart-link' );
	}


	if ( $show_logo ) {
		get_template_part( 'template-parts/logo' );
	}

	if ( $links_position_right ) {
		?>
		<div class="title-links">
		<?php
		if ( $show_cart ) {
			get_template_part( 'template-parts/header-cart-link' );
		}
		get_template_part( 'template-parts/header-menu-toggle' );
		?>
		</div>
		<?php
	} elseif ( 'right' === $menu_position_desktop ) {
		get_template_part( 'template-parts/header-menu-toggle' );
	} elseif ( 'right' === $cart_position_desktop ) {
		get_template_part( 'template-parts/header-cart-link' );
	}
	?>
	<?php if ( ! empty( $menu_animation_follow ) && 'off' !== $menu_animation_follow ) : ?>
	<div class="magic-line <?php echo esc_attr( $menu_animation_follow ); ?>"></div>
	<?php endif; ?>
	</div>
	<?php
endif;
