<?php
/**
 * Site logo template
 *
 * @package Multi
 */

?>
<?php
$logo_link = get_theme_mod( 'multi_logo_link', MULTIMAGAZINE_LOGO_LINK );
$logo_link = empty( $logo_link ) ? home_url( '/' ) : $logo_link;

$classes = array( 'logo' );
$offset  = get_theme_mod( 'multi_logo_v_offset', MULTIMAGAZINE_LOGO_V_OFFSET );
if ( $offset < 0 ) {
	$classes[] = 'offset-up';
} elseif ( $offset > 0 ) {
	$classes[] = 'offset-down';
}

$mobile_offset = get_theme_mod( 'multi_logo_v_offset_mobile', MULTIMAGAZINE_LOGO_V_OFFSET_MOBILE );
if ( $mobile_offset < 0 ) {
	$classes[] = 'mobile-offset-up';
} elseif ( $mobile_offset > 0 ) {
	$classes[] = 'mobile-offset-down';
}

$classes = implode( ' ', $classes );

if ( display_header_text() ) :
	if ( has_custom_logo() ) {
		$custom_logo_id = get_theme_mod( 'custom_logo' );
		$logo           = wp_get_attachment_image_src( $custom_logo_id, 'full' );
		$hover_logo     = get_theme_mod( 'multi_logo_hover_image', MULTIMAGAZINE_LOGO_HOVER_IMAGE );

		if ( ! empty( $hover_logo ) ) {
			$classes .= ' with-hover';
		}

		$logo_width  = get_theme_mod( 'multi_logo_width', MULTIMAGAZINE_LOGO_WIDTH );
		$logo_height = get_theme_mod( 'multi_logo_height', MULTIMAGAZINE_LOGO_HEIGHT );

		if ( empty( $logo_width ) && empty( $logo_height ) ) {
			$logo_width  = $logo[1];
			$logo_height = $logo[2];
		} elseif ( ! empty( $logo_width ) && empty( $logo_height ) ) {
			$logo_height = round( $logo_width * $logo[2] / $logo[1] );

		} elseif ( empty( $logo_width ) && ! empty( $logo_height ) ) {
			$logo_width = round( $logo_height * $logo[1] / $logo[2] );
		}
		$logo_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );



		/** Sticky logo */
		$sticky_logo_id     = get_theme_mod( 'multi_sticky_header_logo', MULTIMAGAZINE_STICKY_HEADER_LOGO );
		$sticky_logo_width  = get_theme_mod( 'multi_sticky_logo_width', MULTIMAGAZINE_STICKY_LOGO_WIDTH );
		$sticky_logo_height = get_theme_mod( 'multi_sticky_logo_height', MULTIMAGAZINE_STICKY_LOGO_HEIGHT );
		$sticky_logo        = wp_get_attachment_image_src( $sticky_logo_id, 'full' );
		?>
		<a href="<?php echo esc_url( $logo_link ); ?>" class="<?php echo esc_attr( $classes ); ?>"><img
		class="main-logo"
		src="<?php echo esc_url( $logo[0] ); ?>"
		<?php if ( $logo_width ) : ?>
			width="<?php echo esc_attr( $logo_width ); ?>"
		<?php endif; ?>
		<?php if ( $logo_height ) : ?>
			height="<?php echo esc_attr( $logo_height ); ?>"
		<?php endif; ?>
		alt="<?php echo esc_attr( $logo_alt ); ?>"
		<?php if ( ! empty( $sticky_logo ) ) : ?>
			data-sticky-logo="<?php echo esc_attr( $sticky_logo[0] ); ?>"
		<?php endif; ?>
		<?php if ( $sticky_logo_width ) : ?>
			data-sticky-logo-width="<?php echo esc_attr( $sticky_logo_width ); ?>"
		<?php endif; ?>
		<?php if ( $sticky_logo_height ) : ?>
			data-sticky-logo-height="<?php echo esc_attr( $sticky_logo_height ); ?>"
		<?php endif; ?>
		aria-hidden="true">
		<?php

		if ( ! empty( $hover_logo ) ) :
			?>
			<img
			class="hover-logo"
			src="<?php echo esc_url( $hover_logo ); ?>"
			<?php if ( $logo_width ) : ?>
			width="<?php echo esc_attr( $logo_width ); ?>"
			<?php endif; ?>
			<?php if ( $logo_height ) : ?>
			height="<?php echo esc_attr( $logo_height ); ?>"
			<?php endif; ?>
			alt="<?php echo esc_attr( $logo_alt ); ?>"
			aria-hidden="true">
			<?php
		endif;
		?>
		</a>
<?php } else { ?>
	<a href="<?php echo esc_url( $logo_link ); ?>" class="<?php echo esc_attr( $classes ); ?>"><?php bloginfo( 'name' ); ?></a>
<?php } ?>

<?php endif; ?>
