<?php
/**
 * CSS vars logic - Header
 *
 * @package Multi
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
}

/**
 * Prepares css variables holding icon properties
 */
function multimagazine_css_vars_header() {
	$css  = '';
	$css .= "--header-height: 0;\n";

	$header_height_top = absint( get_theme_mod( 'multi_header_height_top', MULTIMAGAZINE_HEADER_HEIGHT_TOP ) );
	$header_height_top = empty( $header_height_top ) ? 90 : $header_height_top;

	$css .= '--header-top-height: ' . $header_height_top . "px;\n";

	$header_height_bottom = absint( get_theme_mod( 'multi_header_height_bottom', MULTIMAGAZINE_HEADER_HEIGHT_BOTTOM ) );
	$header_height_bottom = empty( $header_height_bottom ) ? 90 : $header_height_bottom;

	$css .= '--header-bottom-height: ' . $header_height_bottom . "px;\n";

	$sticky_header_height_top = absint( get_theme_mod( 'multi_sticky_header_height_top', MULTIMAGAZINE_STICKY_HEADER_HEIGHT_TOP ) );
	$sticky_header_height_top = empty( $sticky_header_height_top ) ? 90 : $sticky_header_height_top;

	$css .= '--sticky-header-top-height: ' . $sticky_header_height_top . "px;\n";

	$sticky_header_height_bottom = absint( get_theme_mod( 'multi_sticky_header_height_bottom', MULTIMAGAZINE_STICKY_HEADER_HEIGHT_BOTTOM ) );
	$sticky_header_height_bottom = empty( $sticky_header_height_bottom ) ? 90 : $sticky_header_height_bottom;

	$css .= '--sticky-header-bottom-height: ' . $sticky_header_height_bottom . "px;\n";

	$header_height_mobile = absint( get_theme_mod( 'multi_header_height_mobile', $sticky_header_height_top ) );
	if ( empty( $header_height_mobile ) ) {
		$header_height_mobile = $header_height_top;
	}
	$css .= '--header-height-mobile: ' . $header_height_mobile . "px;\n";

	$sticky_header_height_mobile = absint( get_theme_mod( 'multi_sticky_header_height_mobile', MULTIMAGAZINE_STICKY_HEADER_HEIGHT_MOBILE ) );
	$sticky_header_height_mobile = empty( $sticky_header_height_mobile ) ? 'var(--header-height-mobile)' : $sticky_header_height_mobile . 'px';

	$css .= '--sticky-header-height-mobile: ' . $sticky_header_height_mobile . ";\n";

	$header_menu_font = get_theme_mod( 'multi_header_menu_font', MULTIMAGAZINE_HEADER_MENU_FONT );
	$css             .= '--header-menu-font-family: var(--' . $header_menu_font . "-font );\n";

	$header_menu_font_size = absint( get_theme_mod( 'multi_header_menu_font_size', MULTIMAGAZINE_HEADER_MENU_FONT_SIZE ) );
	if ( empty( $header_menu_font_size ) ) {
		$header_menu_font_size = 16;
	}
	$css .= '--header-menu-font-size: ' . $header_menu_font_size . "px;\n";

	$header_menu_font_weight = get_theme_mod( 'multi_header_menu_font_weight', MULTIMAGAZINE_HEADER_MENU_FONT_WEIGHT );
	$css                    .= '--header-menu-font-weight: ' . $header_menu_font_weight . ";\n";

	$header_separator_width = absint( get_theme_mod( 'multi_header_separator_width', MULTIMAGAZINE_HEADER_SEPARATOR_WIDTH ) );

	$css .= '--header-separator-width: ' . $header_separator_width . "px;\n";

	$header_separator_color = get_theme_mod( 'multi_header_separator_color', '' );
	if ( empty( $header_separator_color ) ) {
		global $border_color;
		$header_separator_color = $border_color;
	}
	$css .= '--header-separator-color: ' . $header_separator_color . ";\n";

	$menu_item_spacing = absint( get_theme_mod( 'multi_header_menu_item_spacing', MULTIMAGAZINE_HEADER_MENU_ITEM_SPACING ) );
	$menu_item_padding = absint( get_theme_mod( 'multi_header_menu_item_padding', MULTIMAGAZINE_HEADER_MENU_ITEM_PADDING ) );

	$css .= '--header-menu-item-spacing: ' . multimagazine_css_number( $menu_item_spacing ) . "px;\n";
	$css .= '--header-menu-item-padding: ' . multimagazine_css_number( $menu_item_padding ) . "px;\n";

	$header_menu_separator_width  = absint( get_theme_mod( 'multi_header_menu_separator_width', MULTIMAGAZINE_HEADER_MENU_SEPARATOR_WIDTH ) );
	$header_menu_separator_height = absint( get_theme_mod( 'multi_header_menu_separator_height', MULTIMAGAZINE_HEADER_MENU_SEPARATOR_HEIGHT ) );

	$css .= '--header-menu-separator-width: ' . $header_menu_separator_width . "px;\n";
	$css .= '--header-menu-separator-height: ' . $header_menu_separator_height . "px;\n";

	$header_menu_separator_color = get_theme_mod( 'multi_header_menu_separator_color', '' );
	if ( empty( $header_menu_separator_color ) ) {
		$header_menu_separator_color = 'var(--border-color)';
	}
	$css .= '--header-menu-separator-color: ' . $header_menu_separator_color . ";\n";

	$link_line_thickness = get_theme_mod( 'multi_header_line_thickness', MULTIMAGAZINE_HEADER_LINE_THICKNESS );
	if ( empty( $link_line_thickness ) && 0 !== absint( $link_line_thickness ) ) {
		$link_line_thickness = 3;
	}
	$css .= '--link-line-thickness: ' . $link_line_thickness . "px;\n";

	$link_line_length = absint( get_theme_mod( 'multi_header_line_length', MULTIMAGAZINE_HEADER_LINE_LENGTH ) );
	if ( empty( $link_line_length ) ) {
		$link_line_length = '100%';
	} else {
		$link_line_length .= 'px';
	}
	$css .= '--link-line-length: ' . $link_line_length . ";\n";

	$link_line_v_pos = get_theme_mod( 'multi_header_line_vpos', MULTIMAGAZINE_HEADER_LINE_VPOS );
	switch ( $link_line_v_pos ) {
		case 'top':
			$css .= "--link-line-v-pos: 0px;\n";
			break;
		case 'middle':
			$pos  = ( absint( $header_menu_font_size ) / 2 ) - ( absint( $link_line_thickness ) / 2 ) + 10;
			$css .= '--link-line-v-pos: calc(50% + ' . str_replace( ',', '.', $pos ) . "px);\n";
			break;
		default:
			$css .= "--link-line-v-pos: calc(100% - var(--link-line-thickness));\n";
	}

	$link_line_v_offset = get_theme_mod( 'multi_header_line_v_offset', MULTIMAGAZINE_HEADER_LINE_V_OFFSET );

	$css .= '--link-line-v-offset: ' . intval( $link_line_v_offset ) . "px;\n";

	$header_border_top_width = get_theme_mod( 'multi_header_border_top_width', MULTIMAGAZINE_HEADER_BORDER_TOP_WIDTH );

	$css .= '--header-border-top-width: ' . $header_border_top_width . "px;\n";

	$header_border_bottom_width = get_theme_mod( 'multi_header_border_bottom_width', MULTIMAGAZINE_HEADER_BORDER_BOTTOM_WIDTH );

	$css .= '--header-border-bottom-width: ' . $header_border_bottom_width . "px;\n";

	$header_menu_icon = get_theme_mod( 'multi_header_menu_pulldown_closed', MULTIMAGAZINE_HEADER_MENU_PULLDOWN_CLOSED );

	$css .= "--header-menu-pulldown-icon-closed: '" . $header_menu_icon . "';\n";

	$header_menu_icon_expanded = get_theme_mod( 'multi_header_menu_pulldown_expanded', MULTIMAGAZINE_HEADER_MENU_PULLDOWN_EXPANDED );
	if ( empty( $header_menu_icon_expanded ) || 'rotate' === $header_menu_icon_expanded ) {
		$header_menu_icon_expanded = $header_menu_icon;
	}
	$css .= "--header-menu-pulldown-icon-expanded: '" . $header_menu_icon_expanded . "';\n";

	$header_mobile_bp = get_theme_mod( 'multi_header_mobile_breakpoint', MULTIMAGAZINE_HEADER_MOBILE_BREAKPOINT );
	$header_mobile_bp = empty( $header_mobile_bp ) ? MULTIMAGAZINE_HEADER_MOBILE_BREAKPOINT : $header_mobile_bp;

	$css .= '--header-mobile-breakpoint: ' . absint( $header_mobile_bp ) . "px;\n";

	$header_bg_color = get_theme_mod( 'multi_header_bg_color', MULTIMAGAZINE_HEADER_BG_COLOR );
	$header_bg_color = empty( $header_bg_color ) ? '#ffffff' : $header_bg_color;

	$css .= '--header-background-color: ' . $header_bg_color . ";\n";

	$transparent_header_bg_color = get_theme_mod( 'multi_transparent_header_bg_color', '' );
	$transparent_header_bg_color = empty( $transparent_header_bg_color ) ? 'transparent' : $transparent_header_bg_color;

	$css .= '--header-transparent-background-color: ' . $transparent_header_bg_color . ";\n";

	$sticky_header_bg_color = get_theme_mod( 'multi_sticky_header_background_color', MULTIMAGAZINE_STICKY_HEADER_BACKGROUND_COLOR );
	$sticky_header_bg_color = empty( $sticky_header_bg_color ) ? MULTIMAGAZINE_STICKY_HEADER_BACKGROUND_COLOR : $sticky_header_bg_color;

	$css .= '--sticky-header-background-color: ' . $sticky_header_bg_color . ";\n";

	$header_border_color_top = get_theme_mod( 'multi_header_border_color_top', '#ececec' );
	$header_border_color_top = empty( $header_border_color_top ) ? '#ececec' : $header_border_color_top;

	$css .= '--header-border-color-top: ' . $header_border_color_top . ";\n";

	$header_border_color_bottom = get_theme_mod( 'multi_header_border_color_bottom', '#ececec' );
	$header_border_color_bottom = empty( $header_border_color_bottom ) ? '#ececec' : $header_border_color_bottom;

	$css .= '--header-border-color-bottom: ' . $header_border_color_bottom . ";\n";

	/* header menu colors */

	$header_menu_animation_time = absint( get_theme_mod( 'multi_header_menu_link_animation_time', MULTIMAGAZINE_HEADER_MENU_LINK_ANIMATION_TIME ) );
	$header_menu_animation_time = str_replace( ',', '.', $header_menu_animation_time / 1000 );
	$css                       .= '--menu-animation-time: ' . $header_menu_animation_time . "s;\n";

	$header_link_color = get_theme_mod( 'multi_header_menu_link_color', MULTIMAGAZINE_HEADER_MENU_LINK_COLOR );
	$header_link_color = empty( $header_link_color ) ? '#3f3f3f' : $header_link_color;

	$css .= '--header-link-color: ' . $header_link_color . ";\n";

	$header_link_hover_color = get_theme_mod( 'multi_header_menu_link_hover_color', MULTIMAGAZINE_HEADER_MENU_LINK_HOVER_COLOR );
	$header_link_hover_color = empty( $header_link_hover_color ) ? 'var(--main-color)' : $header_link_hover_color;

	$css .= '--header-link-hover-color: ' . $header_link_hover_color . ";\n";

	$header_pull_down_color = get_theme_mod( 'multi_header_menu_pull_down_icon_color', MULTIMAGAZINE_HEADER_MENU_PULL_DOWN_ICON_COLOR );
	$header_pull_down_color = empty( $header_pull_down_color ) ? '#747474' : $header_pull_down_color;

	$css .= '--header-pull-down-color: ' . $header_pull_down_color . ";\n";

	$header_pull_down_hover_color = get_theme_mod( 'multi_header_menu_pull_down_icon_hover_color', MULTIMAGAZINE_HEADER_MENU_PULL_DOWN_ICON_HOVER_COLOR );
	$header_pull_down_hover_color = empty( $header_pull_down_hover_color ) ? 'var(--header-pull-down-color )' : $header_pull_down_hover_color;

	$css .= '--header-pull-down-hover-color: ' . $header_pull_down_hover_color . ";\n";

	$mobile_pull_down_color = get_theme_mod( 'multi_mobile_menu_pull_down_icon_color', MULTIMAGAZINE_MOBILE_MENU_PULL_DOWN_ICON_COLOR );
	$mobile_pull_down_color = empty( $mobile_pull_down_color ) ? $header_pull_down_color : $mobile_pull_down_color;

	$css .= '--mobile-menu-pull-down-color: ' . $mobile_pull_down_color . ";\n";

	$header_link_border_color = get_theme_mod( 'multi_header_menu_link_border_color', MULTIMAGAZINE_HEADER_MENU_LINK_BORDER_COLOR );
	$header_link_border_color = empty( $header_link_border_color ) ? 'var(--main-color)' : $header_link_border_color;

	$css .= '--header-link-border-color: ' . $header_link_border_color . ";\n";

	$menu_link_bg = get_theme_mod( 'multi_header_menu_link_bg_color', MULTIMAGAZINE_HEADER_MENU_LINK_BG_COLOR );
	$menu_link_bg = empty( $menu_link_bg ) ? 'transparent' : $menu_link_bg;

	$css .= '--header-link-background-color: ' . $menu_link_bg . ";\n";

	$menu_link_hover_bg = get_theme_mod( 'multi_header_menu_link_hover_bg_color', MULTIMAGAZINE_HEADER_MENU_LINK_HOVER_BG_COLOR );
	$menu_link_hover_bg = empty( $menu_link_hover_bg ) ? 'transparent' : $menu_link_hover_bg;

	$css .= '--header-link-background-hover-color: ' . $menu_link_hover_bg . ";\n";

	/* sticky header menu colors */

	$sticky_header_link_color = get_theme_mod( 'multi_sticky_header_menu_link_color', MULTIMAGAZINE_STICKY_HEADER_MENU_LINK_COLOR );
	$sticky_header_link_color = empty( $sticky_header_link_color ) ? 'var(--header-link-color )' : $sticky_header_link_color;

	$css .= '--sticky-header-link-color: ' . $sticky_header_link_color . ";\n";

	$sticky_header_link_hover_color = get_theme_mod( 'multi_sticky_header_menu_link_hover_color', MULTIMAGAZINE_STICKY_HEADER_MENU_LINK_HOVER_COLOR );
	$sticky_header_link_hover_color = empty( $sticky_header_link_hover_color ) ? 'var(--header-link-hover-color )' : $sticky_header_link_hover_color;

	$css .= '--sticky-header-link-hover-color: ' . $sticky_header_link_hover_color . ";\n";

	$sticky_header_pull_down_color = get_theme_mod( 'multi_sticky_header_menu_pull_down_icon_color', MULTIMAGAZINE_STICKY_HEADER_MENU_PULL_DOWN_ICON_COLOR );
	$sticky_header_pull_down_color = empty( $sticky_header_pull_down_color ) ? 'var(--header-pull-down-color )' : $sticky_header_pull_down_color;

	$css .= '--sticky-header-pull-down-color: ' . $sticky_header_pull_down_color . ";\n";

	$sticky_header_pull_down_hover_color = get_theme_mod( 'multi_sticky_header_menu_pull_down_icon_hover_color', MULTIMAGAZINE_STICKY_HEADER_MENU_PULL_DOWN_ICON_HOVER_COLOR );
	$sticky_header_pull_down_hover_color = empty( $sticky_header_pull_down_hover_color ) ? 'var(--header-pull-down-hover-color )' : $sticky_header_pull_down_hover_color;

	$css .= '--sticky-header-pull-down-hover-color: ' . $sticky_header_pull_down_hover_color . ";\n";

	$sticky_header_link_border_color = get_theme_mod( 'multi_sticky_header_menu_link_border_color', MULTIMAGAZINE_STICKY_HEADER_MENU_LINK_BORDER_COLOR );
	$sticky_header_link_border_color = empty( $sticky_header_link_border_color ) ? 'var(--header-link-border-color )' : $sticky_header_link_border_color;

	$css .= '--sticky-header-link-border-color: ' . $sticky_header_link_border_color . ";\n";

	$sticky_menu_link_bg = get_theme_mod( 'multi_sticky_header_menu_link_bg_color', MULTIMAGAZINE_STICKY_HEADER_MENU_LINK_BG_COLOR );
	$sticky_menu_link_bg = empty( $sticky_menu_link_bg ) ? 'var(--header-link-background-color )' : $sticky_menu_link_bg;

	$css .= '--sticky-header-link-background-color: ' . $sticky_menu_link_bg . ";\n";

	$sticky_menu_link_hover_bg = get_theme_mod( 'multi_sticky_header_menu_link_hover_bg_color', MULTIMAGAZINE_STICKY_HEADER_MENU_LINK_HOVER_BG_COLOR );
	$sticky_menu_link_hover_bg = empty( $sticky_menu_link_hover_bg ) ? 'var(--header-link-background-hover-color )' : $sticky_menu_link_hover_bg;

	$css .= '--sticky-header-link-background-hover-color: ' . $sticky_menu_link_hover_bg . ";\n";

	/* submenu/overlayer colors */

	$sm_link_color = get_theme_mod( 'multi_submenu_link_color', '#3f3f3f' );
	$sm_link_color = empty( $sm_link_color ) ? '#3f3f3f' : $sm_link_color;

	$css .= '--submenu-link-color: ' . $sm_link_color . ";\n";

	$sm_link_hover_color = get_theme_mod( 'multi_submenu_link_hover_color', '' );
	$sm_link_hover_color = empty( $sm_link_hover_color ) ? 'var(--main-color)' : $sm_link_hover_color;

	$css .= '--submenu-link-hover-color: ' . $sm_link_hover_color . ";\n";

	$sm_link_bg_color = get_theme_mod( 'multi_submenu_link_background_color', '' );
	if ( empty( $sm_link_bg_color ) ) {
		$sm_link_bg_color = 'transparent';
	}
	$css .= '--submenu-link-background-color: ' . $sm_link_bg_color . ";\n";

	$sm_link_bg_hover_color = get_theme_mod( 'multi_submenu_link_background_hover_color', '' );
	if ( ! empty( $sm_link_bg_hover_color ) ) {
		$css .= '--submenu-link-background-hover-color: ' . $sm_link_bg_hover_color . ";\n";
	}

	$sm_bg_color = get_theme_mod( 'multi_submenu_background_color', '#ffffff' );
	$sm_bg_color = empty( $sm_bg_color ) ? '#ffffff' : $sm_bg_color;

	$css .= '--submenu-background-color: ' . $sm_bg_color . ";\n";
	$css .= '--submenu-overlay-background-color: ' . $sm_bg_color . ";\n";

	$sm_border_color = get_theme_mod( 'multi_submenu_border_color', '#ececec' );
	$sm_border_color = empty( $sm_border_color ) ? '#ececec' : $sm_border_color;

	$css .= '--submenu-border-color: ' . $sm_border_color . ";\n";

	$sm_font_size = get_theme_mod( 'multi_submenu_font_size', MULTIMAGAZINE_SUBMENU_FONT_SIZE );
	if ( empty( $sm_font_size ) ) {
		$sm_font_size = 12;
	}
	$css .= '--submenu-font-size: ' . $sm_font_size . "px;\n";

	/* menu toggle button */
	$menu_toggle_color = get_theme_mod( 'multi_hamburger_icon_color', MULTIMAGAZINE_HAMBURGER_ICON_COLOR );
	$menu_toggle_color = empty( $menu_toggle_color ) ? 'var(--link-color-base )' : $menu_toggle_color;

	$css .= '--hamburger-icon-color: ' . $menu_toggle_color . ";\n";

	$menu_toggle_hover_color = get_theme_mod( 'multi_hamburger_icon_hover_color', MULTIMAGAZINE_HAMBURGER_ICON_HOVER_COLOR );
	$menu_toggle_hover_color = empty( $menu_toggle_hover_color ) ? 'var(--link-color-hover )' : $menu_toggle_hover_color;

	$css .= '--hamburger-icon-hover-color: ' . $menu_toggle_hover_color . ";\n";

	$menu_toggle_bg_color = get_theme_mod( 'multi_hamburger_icon_bg_color', MULTIMAGAZINE_HAMBURGER_ICON_BG_COLOR );
	if ( empty( $menu_toggle_bg_color ) ) {
		$menu_toggle_bg_color = 'transparent';
	}
	$css .= '--hamburger-icon-background-color: ' . $menu_toggle_bg_color . ";\n";

	$menu_toggle_bg_expanded_color = get_theme_mod( 'multi_hamburger_icon_bg_hover_color', MULTIMAGAZINE_HAMBURGER_ICON_BG_HOVER_COLOR );
	$menu_toggle_bg_expanded_color = empty( $menu_toggle_bg_expanded_color ) ? 'transparent' : $menu_toggle_bg_expanded_color;

	$css .= '--hamburger-icon-background-hover-color: ' . $menu_toggle_bg_expanded_color . ";\n";

	return $css;
}
