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

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


/**
 * Prepares css variables holding subheader properties
 */
function multimagazine_css_vars_subheader() {
	$css = '';

	$subheader_bg_id    = get_theme_mod( 'multi_subheader_image', '' );
	$subheader_parallax = get_theme_mod( 'multi_subheader_parallax', MULTIMAGAZINE_SUBHEADER_PARALLAX );
	$height             = $subheader_parallax ? 1080 : 100;
	$subheader_bg       = wp_get_attachment_image_url( $subheader_bg_id, array( 1920, $height ) );
	$subheader_bg       = empty( $subheader_bg ) ? 'none' : 'url( ' . esc_url( $subheader_bg ) . ' )';

	$css .= '--subheader-bg-image: ' . esc_attr( $subheader_bg ) . ";\n";

	$subheader_bg_size = get_theme_mod( 'multi_subheader_background_size', MULTIMAGAZINE_SUBHEADER_BACKGROUND_SIZE );
	if ( empty( $subheader_bg_size ) ) {
		$subheader_bg_size = 'auto';
	}
	$subheader_custom_bg_size = get_theme_mod( 'multi_subheader_custom_background_size', MULTIMAGAZINE_SUBHEADER_CUSTOM_BACKGROUND_SIZE );
	if ( 'custom' === $subheader_bg_size && ! empty( $subheader_custom_bg_size ) ) {

		$css .= '--subheader-custom-bg-size: ' . esc_attr( $subheader_custom_bg_size ) . ";\n";

		$subheader_bg_size = 'var(--subheader-custom-bg-size )';
	}
	$css .= '--subheader-bg-size: ' . esc_attr( $subheader_bg_size ) . ";\n";

	$subheader_bg_color = get_theme_mod( 'multi_subheader_background_color', MULTIMAGAZINE_SUBHEADER_BACKGROUND_COLOR );
	if ( empty( $subheader_bg_color ) ) {
		$subheader_bg_color = 'transparent';
	}
	$css .= '--subheader-bg-color: ' . esc_attr( $subheader_bg_color ) . ";\n";

	$subheader_text_color = get_theme_mod( 'multi_subheader_text_color', MULTIMAGAZINE_SUBHEADER_TEXT_COLOR );
	if ( empty( $subheader_text_color ) ) {
		$subheader_text_color = 'var(--text-color-base)';
	}
	$css .= '--subheader-text-color: ' . esc_attr( $subheader_text_color ) . ";\n";

	$subheader_link_color = get_theme_mod( 'multi_subheader_link_color', MULTIMAGAZINE_SUBHEADER_LINK_COLOR );
	if ( empty( $subheader_link_color ) ) {
		$subheader_link_color = 'var(--link-color-base)';
	}
	$css .= '--subheader-link-color: ' . esc_attr( $subheader_link_color ) . ";\n";

	$subheader_link_hover_color = get_theme_mod( 'multi_subheader_link_hover_color', MULTIMAGAZINE_SUBHEADER_LINK_HOVER_COLOR );
	if ( empty( $subheader_link_hover_color ) ) {
		$subheader_link_hover_color = 'var(--link-color-hover)';
	}
	$css .= '--subheader-link-hover-color: ' . esc_attr( $subheader_link_hover_color ) . ";\n";

	return $css;
}

