<?php
/**
 * Prints Customizer-driven frontend CSS.
 *
 * Outputs Kirki-generated control CSS, CSS custom properties for theme colors,
 * header/hamburger visibility rules, per-page content padding and menu scheme
 * overrides, and responsive breakpoint styles. Included via output buffering
 * from `Eronex_Customizer_Config::frontend_inline_css()`.
 *
 * @package Eronex
 * @since   0.0.1
 */

use Kirki\Compatibility\Kirki;

$p_id = get_the_ID();

//Header
$header_style      = eronex_option( 'eronex_header_style', '1' );
$hamburger_show_on = eronex_option( 'eronex_hamburger_show_on', 'tablet' );

//Responsive Breakpoints
$tablet_breakpoint_option = eronex_option( 'eronex_tablet_breakpoint', 1025 );
$mobile_breakpoint_option = eronex_option( 'eronex_mobile_breakpoint', 767 );

$tablet_breakpoint = ! empty( $tablet_breakpoint_option ) ? $tablet_breakpoint_option : 1025;
$mobile_breakpoint = ! empty( $mobile_breakpoint_option ) ? $mobile_breakpoint_option : 767;

$configs = Kirki::$config;
foreach ( $configs as $config_id => $args ) {
	$styles = Kirki_Modules_CSS::loop_controls( $config_id );
	if ( ! empty( $styles ) ) {
		echo wp_kses_post( wp_strip_all_tags( $styles ) );
	}
}


$primary_color = eronex_option( 'eronex_primary_color', '#7E4CFF' );
$primary_color = eronex_hex_to_rgb( $primary_color ?? '#7E4CFF', false, 0 );

$secondary_color = eronex_option( 'eronex_secondary_color', '#2E80FF' );
$secondary_color = eronex_hex_to_rgb( $secondary_color ?? '#2E80FF', false, 0 );

$body_text_color = eronex_option( 'eronex_primary_font_color', '#636363' );
$body_text_color = eronex_hex_to_rgb( $body_text_color ?? '#636363', false, 0 );

$heading_text_color = eronex_option( 'eronex_secondary_font_color', '#0E0E0F' );
$heading_text_color = eronex_hex_to_rgb( $heading_text_color ?? '#0E0E0F', false, 0 );

//Desktop
?>
:root{
	--eronex-primary-color: <?php echo esc_attr( $primary_color ); ?>;
	--eronex-secondary-color: <?php echo esc_attr( $secondary_color ); ?>;
	--eronex-primary-font-color: <?php echo esc_attr( $body_text_color ); ?>;
	--eronex-secondary-font-color: <?php echo esc_attr( $heading_text_color ); ?>;
}
<?php if ( 'desktop' === $hamburger_show_on ) { ?>
	.eronex-header .eronex-hamburger-toggle-btn{
		display: inline-flex;
	}
	<?php
}

$content_padding = get_post_meta( $p_id, 'eronex_content_padding', true );

if ( 'no' === $content_padding ) {
	?>
	body.page-id-<?php echo esc_attr( $p_id ); ?> .eronex-content-inner{
		padding-top: 0;
		padding-bottom: 0;
	}
	<?php
}

$header_menu_scheme = get_post_meta( $p_id, 'eronex_header_menu_scheme', true );

if ( 'light' === $header_menu_scheme ) {
	?>
	body.page-id-<?php echo esc_attr( $p_id ); ?> .eronex-navbar nav > ul > li > a{
		color: #ffffff;
	}
	<?php
} elseif ( 'dark' === $header_menu_scheme ) {
	?>
	body.page-id-<?php echo esc_attr( $p_id ); ?> .eronex-navbar nav > ul > li > a{
		color: rgb(var(--eronex-secondary-font-color));
	}
	<?php
}

//Tablet Min Breakpoint
?>
@media screen and (min-width: <?php echo esc_attr( $tablet_breakpoint_option ); ?>px) {
	.eronex-header:has(.eronex-navbar-style-5) {
		min-height: auto !important;
	}

	.eronex-header:not(.eronex-appear) .eronex-navbar-style-5 {
		width: 100%;
		max-width: 1140px;
		margin: 0 auto;
		position: absolute;
		top: 32px;
		z-index: 99;
		left: 50%;
		transform: translateX(-50%);
		border-radius: var(--eronex-border-radius-lg);
	}
	.eronex-aside-left{
		order: -1;
	}
}
<?php

//Tablet Max Breakpoint
?>
@media screen and (max-width: <?php echo esc_attr( $tablet_breakpoint_option ); ?>px) {

	.eronex-row:has(.eronex-aside) .eronex-main {
		width: 100%;
	}

	.eronex-row .eronex-aside {
		width: 100%;
	}


	<?php if ( 'tablet' === $hamburger_show_on ) { ?>
		.eronex-header .eronex-hamburger-toggle-btn{
			display: inline-flex;
		}
		.eronex-header .eronex-nav > .eronex-menu{
			display: none;
		}
	<?php } ?>

}
<?php

//Mobile Max Breakpoints
?>
@media screen and (max-width: <?php echo esc_attr( $mobile_breakpoint_option ); ?>px) {

	<?php if ( 'mobile' === $hamburger_show_on ) { ?>
		.eronex-header .eronex-hamburger-toggle-btn{
			display: inline-flex;
		}
		.eronex-header .eronex-nav > .eronex-menu{
			display: none;
		}
	<?php } ?>

}