<?php
// Enqueue theme styles and custom inline CSS
function home_shifting_services_enqueue_styles() {
    wp_enqueue_style('home-shifting-services-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'home_shifting_services_enqueue_styles');

// custom header
    add_theme_support('custom-header', array(
            'width'                  => 1920, 
            'height'                 => 400,  
            'flex-height'            => true,
            'flex-width'             => true,
            'header-text'            => true, // Enable or disable header text
            'default-text-color'     => '000000', // Default header text color
            'wp-head-callback'       => 'home_shifting_services_header_style',
        ) );

// custom-background
    add_theme_support( 'custom-background', array(
          'default-color' => 'ffffff',
        ));

// Style the header
function home_shifting_services_header_style() {
    $home_shifting_services_header_image = get_header_image();    
    $home_shifting_services_header_text_color = get_header_textcolor();
   
     if (get_theme_support('custom-header', 'default-text-color') !== $home_shifting_services_header_text_color || !empty($home_shifting_services_header_image)) {
            ?>
        <style type="text/css" id="entr-header-css">
            <?php
            // Has a Custom Header been added?
            if (!empty($home_shifting_services_header_image)) :
                ?>
                 #custom-header {
                    background-image: url(<?php header_image(); ?>);
                    background-repeat: no-repeat;
                    background-position: 50% 50%;
                    -webkit-background-size: cover;
                    -moz-background-size:    cover;
                    -o-background-size:      cover;
                    background-size:         cover;
                }
            <?php endif; ?> 
            <?php
                if ('blank' === $home_shifting_services_header_text_color) :
                ?>
                    .site-title a,.site-description {
                        color: #<?php echo esc_attr( $home_shifting_services_header_text_color ); ?>;
                    }
                <?php elseif ('' !== $home_shifting_services_header_text_color) : ?>
                    .site-title a,.site-description {
                        color: #<?php echo esc_attr($home_shifting_services_header_text_color); ?>;
                    }            
                <?php endif; ?>
        </style>
    <?php
        }
    }
// site-title-checkbox
// Remove "Display Site Title and Tagline" checkbox from Customizer
function home_shifting_services_remove_header_text_display_checkbox( $wp_customize ) {
    $wp_customize->remove_control( 'display_header_text' ); // Removes the checkbox
}
add_action( 'customize_register', 'home_shifting_services_remove_header_text_display_checkbox', 11 );

/**
* Custom logo
*/
function home_shifting_services_logo_setup(){
    add_theme_support('custom-logo', array(
        'height' => 65,
        'width' => 350,
        'flex-height' => true,
        'flex-width' => true,
    ));
}
add_action('after_setup_theme', 'home_shifting_services_logo_setup');


// logo-resizer
function home_shifting_services_logo_dynamic_css() {
    $home_shifting_services_logo_width = get_theme_mod( 'home_shifting_services_logo_width', 150 );
    ?>
    <style type="text/css">
        .logo .custom-logo {
            max-width: <?php echo esc_attr( $home_shifting_services_logo_width ); ?>px;
            height: auto;
        }
    </style>
    <?php
}
add_action( 'wp_head', 'home_shifting_services_logo_dynamic_css' );

// buttons
function home_shifting_services_custom_button_styles() {
    $home_shifting_services_radius = get_theme_mod( 'home_shifting_services_button_border_radius', '5px' );
    $home_shifting_services_padding = get_theme_mod( 'home_shifting_services_button_padding', '15px 15px' );
    ?>
    <style type="text/css">
        .btn,
        .button,
        button,
        input[type="submit"],
        .wp-block-button__link,#blog-section .read-more a,.read-more a,a.btn-slid.btn,a.btn-slid2.btn,a.btn-solut.btn {
            border-radius: <?php echo esc_attr($home_shifting_services_radius); ?>;
            padding: <?php echo esc_attr($home_shifting_services_padding); ?>;
        }
    </style>
    <?php
}
add_action( 'wp_head', 'home_shifting_services_custom_button_styles' );

function home_shifting_services_customize_fonts() {
    $home_shifting_services_body_font = get_theme_mod('home_shifting_services_body_font_family', 'Poppins, sans-serif');
    $home_shifting_services_heading_font = get_theme_mod('home_shifting_services_heading_font_family', 'Poppins, sans-serif');

    // Extract Google font names (e.g., Roboto from "Roboto, sans-serif")
    $home_shifting_services_body_font_name = trim(explode(',', $home_shifting_services_body_font)[0]);
    $home_shifting_services_heading_font_name = trim(explode(',', $home_shifting_services_heading_font)[0]);

    // Generate Google Fonts URL
    $home_shifting_services_google_font_url = 'https://fonts.googleapis.com/css2?family=' . urlencode($home_shifting_services_body_font_name) . '&family=' . urlencode($home_shifting_services_heading_font_name) . '&display=swap';

    // Enqueue fonts
    wp_enqueue_style('home-shifting-services-fonts', $home_shifting_services_google_font_url, array(), null);

    // Custom inline style for font application
    $custom_css = "
        body, p, span, label, div {
            font-family: {$home_shifting_services_body_font};
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: {$home_shifting_services_heading_font};
        }
    ";
    wp_add_inline_style('home-shifting-services-fonts', $custom_css);
}
add_action('wp_enqueue_scripts', 'home_shifting_services_customize_fonts');

// page title box
function home_shifting_services_page_title_dynamic_styles() {
    $bg_type = get_theme_mod('home_shifting_services_page_bg_radio', '');
    $bg_color = get_theme_mod('home_shifting_services_page_bg_color', '');
    $bg_image = get_theme_mod('home_shifting_services_page_bg_image', '');
    $global_color = get_theme_mod('home_shifting_services_global_color1', '#f70643');

    $home_shifting_services_dynamic_css = '';

    if ($bg_type === 'image' && !empty($bg_image)) {
        $home_shifting_services_dynamic_css .= '.page-title {';
        $home_shifting_services_dynamic_css .= 'background-image: url("' . esc_url($bg_image) . '");';
        $home_shifting_services_dynamic_css .= 'background-size: cover;';
        $home_shifting_services_dynamic_css .= 'background-position: center;';
        $home_shifting_services_dynamic_css .= '}';
    } elseif ($bg_type === 'color' && !empty($bg_color)) {
        $home_shifting_services_dynamic_css .= '.page-title {';
        $home_shifting_services_dynamic_css .= 'background-color: ' . esc_attr($bg_color) . ';';
        $home_shifting_services_dynamic_css .= '}';
    } else {
        // Fallback to global theme color
        $home_shifting_services_dynamic_css .= '.page-title {';
        $home_shifting_services_dynamic_css .= 'background-color: ' . esc_attr($global_color) . ';';
        $home_shifting_services_dynamic_css .= '}';
    }

    if (!empty($home_shifting_services_dynamic_css)) {
        echo '<style type="text/css">' . $home_shifting_services_dynamic_css . '</style>';
    }
}
add_action('wp_head', 'home_shifting_services_page_title_dynamic_styles', 20);

// global color
function home_shifting_services_global_color_custom_css() {
    $home_shifting_services_whole_color   = get_theme_mod('home_shifting_services_global_color1', '#f70643');
    $home_shifting_services_heading_color = get_theme_mod('home_shifting_services_global_color2', '#2f2c2b');
    $home_shifting_services_bg_type       = get_theme_mod('home_shifting_services_page_bg_radio', 'color');

    $home_shifting_services_theme_css = '';

    if (!empty($home_shifting_services_whole_color)) {
        // Apply global background only if no custom bg for page-title
        if ($home_shifting_services_bg_type !== 'color' && $home_shifting_services_bg_type !== 'image') {
            $home_shifting_services_theme_css .= '.page-title .content-section{ background: ' . esc_attr($home_shifting_services_whole_color) . '; }';
        }

        $home_shifting_services_theme_css .= '#footer,#sidebar-wrapper h3, #sidebar-wrapper label.wp-block-search__label, #sidebar-wrapper .widget_block h3, #sidebar-wrapper h2, #sidebar-wrapper label.wp-block-search__label,.wp-block-file .wp-block-file__button,.wp-block-button .wp-block-button__link,#footer select,a.btntoTop:hover,a.wc-block-components-button.wp-element-button.wc-block-cart__submit-button.contained,#blog-section .read-more a,.post-tags a:hover,.blog .pagination .nav-links .current,.woocommerce .woocommerce-info .button,button.woocommerce-Button.button,.woocommerce span.onsale,.woocommerce div.product form.cart .button,.woocommerce ul.products li.product .button,.wc-block-grid__product-add-to-cart .wp-block-button__link,button,input[type="submit"],aside form #searchsubmit,#sidebar-wrapper ul li:not(.recentcomments) a:before,div#topbar,a.hdr-btn,a.btn-slid.btn,a.btn-slid2.btn:hover,.slider-sec .owl-carousel button.owl-dot.active,select.gt_selector,.tbr-languge,.solu-title,.inn-sidebar ul li:not(.recentcomments) a:before,.detail-sidebar ul li:not(.recentcomments) a:before,.inn-sidebar label.wp-block-search__label,.inn-sidebar h2,.inn-sidebar h3,.inn-sidebar .widget_bloc h3,.detail-sidebar h3,.detail-sidebar .widget_block h3,.detail-sidebar h2,.detail-sidebar label.wp-block-search__label{';
        $home_shifting_services_theme_css .= 'background: ' . esc_attr($home_shifting_services_whole_color) . ';';
        $home_shifting_services_theme_css .= '}';

        $home_shifting_services_theme_css .= 'textarea,#sidebar-wrapper .widget ul li a, #footer .footer-widgets .widget ul li a, #footer .footer-widgets .section ul li a,div#sidebar-wrapper .wp-block-latest-comments__comment-author, div#sidebar-wrapper .wp-block-latest-comments__comment-link,.loader-pulse,.main-navigation .menu > li > a:hover,.woocommerce.widget_shopping_cart .buttons a,#footer .wp-block-button__link,div.footer-widgets-wrapper p.wp-block-tag-cloud a,div.footer-widgets-wrapper .tagcloud a,p.wp-block-tag-cloud a,div.footer-widgets-wrapper .tag-cloud a,#blog-section .meta a,#blog-section .meta span,#blog-section .meta span,#blog-section .meta span a,.nav-previous a .post-title,.nav-next a .post-title,aside #searchform div,.woocommerce ul.products li.product .price,.detail-sidebar ul li a:hover,.inn-sidebar ul li a:hover,.woocommerce-My,#site-navigation .menu ul li a:hover,.page_item_has_children ul li a,.main-navigation .menu .menu-item-has-children ul li a,.main-navigation li.current_page_item > a, .main-navigation li.current-menu-item > a,.woocommerce-MyAccount-content a,.wp-block-file .wp-block-file__button,.wp-block-button.is-style-outline .wp-block-button__link,a.btntoTop,div#sidebar-wrapper .widget ul li a,div#sidebar-wrapper select,div#sidebar-wrapper p.wp-block-tag-cloud a:before,div#sidebar-wrapper .tagcloud a:before,div#sidebar-wrapper p.wp-block-tag-cloud a:before,div#sidebar-wrapper p.wp-block-tag-cloud a,div#sidebar-wrapper .tagcloud a,div#sidebar-wrapper p.wp-block-tag-cloud a,div#sidebar-wrapper .widget ul li,.footer-widgets .widget ul li,.blog-cat li a:hover,a.hdr-btn:hover,.search-icon,h2#banner-heading span,.inn-sidebar .wp-block-latest-comments__comment-author,.inn-sidebar .wp-block-latest-comments__comment-link,.detail-sidebar .wp-block-latest-comments__comment-author,.detail-sidebar .wp-block-latest-comments__comment-link,.inn-sidebar .widget ul li a,.detail-sidebar .widget ul li a,.inn-sidebar ul li:hover,.detail-sidebar ul li:hover,.inn-sidebar p.wp-block-tag-cloud a:before,.inn-sidebar .tagcloud a:before,.inn-sidebar p.wp-block-tag-cloud a:before,.detail-sidebar p.wp-block-tag-cloud a:before,.detail-sidebar .tagcloud a:before,.detail-sidebar p.wp-block-tag-cloud a:before,.inn-sidebar .tagcloud a,.detail-sidebar .tagcloud a{';
        $home_shifting_services_theme_css .= 'color: ' . esc_attr($home_shifting_services_whole_color) . ';';
        $home_shifting_services_theme_css .= '}';

        $home_shifting_services_theme_css .= 'a.btntoTop,nav.woocommerce-MyAccount-navigation ul li,.wp-block-file .wp-block-file__button,.wp-block-button.is-style-outline .wp-block-button__link,.wp-block-pullquote blockquote,.wp-block-quote:not(.is-large):not(.is-style-large),div.footer-widgets-wrapper p.wp-block-tag-cloud a,div.footer-widgets-wrapper .tagcloud a,p.wp-block-tag-cloud a,div.footer-widgets-wrapper .tag-cloud a,a.hdr-btn:hover{';
        $home_shifting_services_theme_css .= 'border-color: ' . esc_attr($home_shifting_services_whole_color) . ';';
        $home_shifting_services_theme_css .= '}';
    }

    if (!empty($home_shifting_services_heading_color)) {
        $home_shifting_services_theme_css .= 'h1,h2,h3,h4,h5,h6,h2.entry-title a,header.style1 .logo h1.site-title a,.logo p.site-title a,.follow-us i:hover,a.topbr-ltr-btn:hover,a.career-btn:hover,h3.soltn-main-hd,h6.soltn-sm-hd{';
        $home_shifting_services_theme_css .= 'color: ' . esc_attr($home_shifting_services_heading_color) . ';';
        $home_shifting_services_theme_css .= '}';
    }

    if (!empty($home_shifting_services_theme_css)) {
        echo '<style type="text/css">' . $home_shifting_services_theme_css . '</style>';
    }
}
add_action('wp_head', 'home_shifting_services_global_color_custom_css', 10);

