<?php

function relax_spa_dynamic_css() {
    wp_enqueue_style(
        'relax-spa-style',
        get_stylesheet_uri(),
        array(),
        RELAX_SPA_VERSION
    );
    $site_title_color = get_theme_mod( 'bs_site_title_color_option', '#000' );
    $site_title_size = get_theme_mod( 'bs_site_title_size', '30' );
    $logo_size = absint( $site_title_size * 2 );
    $site_identity_font_family = get_theme_mod( 'bs_site_identity_font_family', 'Dancing Script' );
    $primary_color = relax_spa_hex_to_rgba( get_theme_mod( 'primary_color', '#2C396B' ) );
    $secondary_color = relax_spa_hex_to_rgba( get_theme_mod( 'secondary_color', '#DBAE95' ) );
    $dark_color = relax_spa_hex_to_rgba( '#000000' );
    $light_color = relax_spa_hex_to_rgba( '#ffffff' );
    $text_color = relax_spa_hex_to_rgba( '#757575' );
    $body_font_family = esc_attr( get_theme_mod( 'body_font_family', 'Mulish' ) );
    $font_size = esc_attr( get_theme_mod( 'font_size', '16px' ) );
    $body_font_weight = esc_attr( get_theme_mod( 'body_font_weight', 400 ) );
    $body_line_height = get_theme_mod( 'body_line_height', '1.5' );
    $heading_font_family = esc_attr( get_theme_mod( 'heading_font_family', 'Poppins' ) );
    $topheading_font_family = esc_attr( get_theme_mod( 'topheading_font_family', 'Caveat' ) );
    $topheading_font_size = esc_attr( get_theme_mod( 'relax_spa_topheading_size', 22 ) );
    $heading_font_weight = esc_attr( get_theme_mod( 'relax_spa_heading_font_weight', 600 ) );
    $default_size = array(
        '1' => 80,
        '2' => 34,
        '3' => 30,
        '4' => 26,
        '5' => 24,
        '6' => 18,
    );
    for ($i = 1; $i <= 6; $i++) {
        $heading[$i] = absint( get_theme_mod( 'relax_spa_heading_' . $i . '_size', absint( $default_size[$i] ) ) );
    }
    $dynamic_css = "\n        :root {\n                --primary-color: {$primary_color};\n                --secondary-color: {$secondary_color};\n                --dark-color: {$dark_color};\n                --light-color: {$light_color};\n                --text-color: {$text_color};\n\n                --body-font: {$body_font_family};\n                --heading-font: {$heading_font_family};\n                --topheading-font: {$topheading_font_family};\n                --heading-weight: {$heading_font_weight};\n               \n                --h1-size: {$heading[1]}px;\n                --h2-size: {$heading[2]}px;\n                --h3-size: {$heading[3]}px;\n                --h4-size: {$heading[4]}px;\n                --h5-size: {$heading[5]}px;\n                --h6-size: {$heading[6]}px; \n\n                --preheading-size: {$topheading_font_size}px;\n               \n        }\n        /* site title size */\n        .site-title a{ font-size: {$site_title_size}" . "px; font-family: {$site_identity_font_family}; color: {$site_title_color}; }\n        \n        header .custom-logo-link img{ height: {$logo_size}" . "px; }\n\n        /* font family */\n        html,:root{ font-size: {$font_size};}\n\n        body{line-height: {$body_line_height};  font-weight:{$body_font_weight}; }              \n        ";
    wp_add_inline_style( 'relax-spa-style', $dynamic_css );
}

add_action( 'wp_enqueue_scripts', 'relax_spa_dynamic_css' );