<?php

// In your theme's functions.php or equivalent
add_action('customize_controls_enqueue_scripts', function() {
    $version = wp_get_theme()->get('Version');
    
    // Define parameters
    $customizer_params = array(
        'some_key' => 'some_value', // Add your parameters here
    );
    
    wp_enqueue_script(
        'supermarket-shopping-customize-section-button',
        get_theme_file_uri('assets/js/customize-controls.js'),
        ['customize-controls'],
        $version,
        true
    );

    wp_enqueue_style(
        'supermarket-shopping-customize-section-button',
        get_theme_file_uri('assets/css/customize-controls.css'),
        ['customize-controls'],
        $version
    );

    wp_localize_script(
        'supermarket-shopping-customize-section-button',
        'supermarket_shopping_customizer_params',
        $customizer_params
    );
});


 /**
 * Enqueue scripts and styles.
 */
function supermarket_shopping_scripts() {
	// Styles	 

	wp_enqueue_style('bootstrap-min',get_template_directory_uri().'/assets/css/bootstrap.min.css');

	// owl
	wp_enqueue_style( 'owl-carousel-css', get_theme_file_uri( '/assets/css/owl.carousel.css' ) );
		
	wp_enqueue_style( 'font-awesome', get_template_directory_uri().'/assets/css/fontawesome-all.css' );
	
	wp_enqueue_style('supermarket-shopping-editor-style',get_template_directory_uri().'/assets/css/editor-style.css');

	wp_enqueue_style('supermarket-shopping-main', get_template_directory_uri() . '/assets/css/main.css');

	wp_enqueue_style('supermarket-shopping-woo', get_template_directory_uri() . '/assets/css/woo.css');
	
	wp_enqueue_style( 'supermarket-shopping-style', get_stylesheet_uri() );


	wp_enqueue_style('supermarket-shopping-main', get_stylesheet_uri(), array() );
		wp_style_add_data('supermarket-shopping-main', 'rtl', 'replace');
	
	// Scripts

	wp_enqueue_script('bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.bundle.min.js', array('jquery'), false, true);

	wp_enqueue_script('supermarket-shopping-theme-js', get_template_directory_uri() . '/assets/js/theme.js', array('jquery'), false, true);

	wp_enqueue_script( 'owl-carousel-js', get_theme_file_uri( '/assets/js/owl.carousel.js' ), array( 'jquery' ), true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

    // Animations
    if ( get_theme_mod( 'supermarket_shopping_animation_enabled', true ) ) {
        wp_enqueue_script('wow-js', get_theme_file_uri('/assets/js/wow.js'), array('jquery'), null, true);
        wp_enqueue_style('animate-css', get_template_directory_uri() . '/assets/css/animate.css');
    }

	// inlin css
	$supermarket_shopping_inline_style = '';

	$supermarket_shopping_slider_setting = get_theme_mod( 'supermarket_shopping_slider_setting', false);
	if($supermarket_shopping_slider_setting == false) {
	    $supermarket_shopping_inline_style .= '.page-template-template-frontpage .middle-header-area{';
	    $supermarket_shopping_inline_style .= 'position:static; border-bottom:1px solid #ccc;';
	    $supermarket_shopping_inline_style .= '}';
	}

	wp_add_inline_style( 'supermarket-shopping-style', $supermarket_shopping_inline_style );

}
add_action( 'wp_enqueue_scripts', 'supermarket_shopping_scripts' );

// Function to enqueue custom CSS
function supermarket_shopping_enqueue_custom_css() {

    $handle = 'supermarket-shopping-style';

    // Get the generated custom CSS
    $supermarket_shopping_custom_css = "";

    $supermarket_shopping_blog_layouts = get_theme_mod(
        'supermarket_shopping_blog_layout_option_setting',
        'Default'
    );

    if ($supermarket_shopping_blog_layouts == 'Default') {

        $supermarket_shopping_custom_css .= '.blog-item{';
        $supermarket_shopping_custom_css .= 'text-align:center;';
        $supermarket_shopping_custom_css .= '}';

    } elseif ($supermarket_shopping_blog_layouts == 'Left') {

        $supermarket_shopping_custom_css .= '.blog-item{';
        $supermarket_shopping_custom_css .= 'text-align:left;';
        $supermarket_shopping_custom_css .= '}';

    } elseif ($supermarket_shopping_blog_layouts == 'Right') {

        $supermarket_shopping_custom_css .= '.blog-item{';
        $supermarket_shopping_custom_css .= 'text-align:right;';
        $supermarket_shopping_custom_css .= '}';

    }



    // slider css
    $supermarket_shopping_slider_setting =
        get_theme_mod(
            'supermarket_shopping_slider_setting',
            false
        );

    if ($supermarket_shopping_slider_setting == false) {

        $supermarket_shopping_custom_css .=
        '.page-template-template-frontpage .lower-part{';
        $supermarket_shopping_custom_css .=
        'position:static;';
        $supermarket_shopping_custom_css .= '}';

    }



    // slider arrows css
    $supermarket_shopping_slider_arrows =
        get_theme_mod(
            'supermarket_shopping_slider_setting',
            false
        );

    if ($supermarket_shopping_slider_arrows == false) {

        $supermarket_shopping_custom_css .=
        '.page-template-template-frontpage .menubox{';
        $supermarket_shopping_custom_css .=
        'position:static;';
        $supermarket_shopping_custom_css .= '}';

    }



// ------------logo

    $supermarket_shopping_site_title_font_size =
        get_theme_mod(
            'supermarket_shopping_site_title_font_size',
            30
        );

    $supermarket_shopping_custom_css .=
    '.logo h1 a, .logo p a{';
    $supermarket_shopping_custom_css .=
    'font-size:' .
    esc_attr(
        $supermarket_shopping_site_title_font_size
    ) .
    'px !important;';
    $supermarket_shopping_custom_css .= '}';



    // Site Tagline Font Size

    $supermarket_shopping_site_tagline_font_size =
        get_theme_mod(
            'supermarket_shopping_site_tagline_font_size',
            15
        );

    $supermarket_shopping_custom_css .=
    '.logo p{';
    $supermarket_shopping_custom_css .=
    'font-size:' .
    esc_attr(
        $supermarket_shopping_site_tagline_font_size
    ) .
    'px;';
    $supermarket_shopping_custom_css .= '}';



    // logo title color

    $supermarket_shopping_site_tagline_color =
        get_theme_mod(
            'supermarket_shopping_site_tagline_color'
        );

    if (
        $supermarket_shopping_site_tagline_color
        != false
    ) {

        $supermarket_shopping_custom_css .=
        '.logo h1 a,
         .logo p a,
         .logo p.site-title a{';

        $supermarket_shopping_custom_css .=
        'color:' .
        esc_attr(
            $supermarket_shopping_site_tagline_color
        ) .
        ' !important;';

        $supermarket_shopping_custom_css .= '}';

    }



    // tagline color

    $supermarket_shopping_logo_tagline_color =
        get_theme_mod(
            'supermarket_shopping_logo_tagline_color'
        );

    if (
        $supermarket_shopping_logo_tagline_color
        != false
    ) {

        $supermarket_shopping_custom_css .=
        'p.site-description{';

        $supermarket_shopping_custom_css .=
        'color:' .
        esc_attr(
            $supermarket_shopping_logo_tagline_color
        ) .
        ' !important;';

        $supermarket_shopping_custom_css .= '}';

    }



// ---------- Scroll Top

    $supermarket_shopping_scroll_top_bg_color =
        get_theme_mod(
            'supermarket_shopping_scroll_top_bg_color',
            '#DB9A11'
        );

    $supermarket_shopping_scroll_top_color =
        get_theme_mod(
            'supermarket_shopping_scroll_top_color',
            '#fff'
        );

    if (
        $supermarket_shopping_scroll_top_bg_color
        === '#DB9A11'
    ) {

        $supermarket_shopping_scroll_top_bg_color =
            get_theme_mod(
                'supermarket_shopping_dynamic_color_one'
            );

    }

    $supermarket_shopping_custom_css .=
    '#scrolltop{';
    $supermarket_shopping_custom_css .=
    'background-color:' .
    $supermarket_shopping_scroll_top_bg_color .
    ';';
    $supermarket_shopping_custom_css .= '}';

    $supermarket_shopping_custom_css .=
    '#scrolltop span{';
    $supermarket_shopping_custom_css .=
    'color:' .
    $supermarket_shopping_scroll_top_color .
    ';';
    $supermarket_shopping_custom_css .= '}';



// ---------- Preloader

    $supermarket_shopping_preloader_bg_color =
        get_theme_mod(
            'supermarket_shopping_preloader_bg_color',
            '#ffffff'
        );

    $supermarket_shopping_preloader_color =
        get_theme_mod(
            'supermarket_shopping_preloader_color',
            '#DB9A11'
        );

    if (
        $supermarket_shopping_preloader_color
        === '#DB9A11'
    ) {

        $supermarket_shopping_preloader_color =
            get_theme_mod(
                'supermarket_shopping_dynamic_color_one'
            );

    }

    $supermarket_shopping_custom_css .=
    '.loading{';
    $supermarket_shopping_custom_css .=
    'background-color:' .
    $supermarket_shopping_preloader_bg_color .
    ';';
    $supermarket_shopping_custom_css .= '}';

    $supermarket_shopping_custom_css .=
    '.loader{';
    $supermarket_shopping_custom_css .=
    'border-color:' .
    $supermarket_shopping_preloader_color .
    ';';
    $supermarket_shopping_custom_css .=
    'color:' .
    $supermarket_shopping_preloader_color .
    ';';
    $supermarket_shopping_custom_css .= '}';



//  add only once
    wp_add_inline_style(
        $handle,
        $supermarket_shopping_custom_css
    );

     // footer copyright
    $supermarket_shopping_footer_font_size = get_theme_mod('supermarket_shopping_footer__bottom_copyright_text_font_size');
    $supermarket_shopping_footer_padding = get_theme_mod('supermarket_shopping_footer__bottom_copyright_text_top_bottom_padding');

    if ( $supermarket_shopping_footer_font_size === '14px' ) {
        $supermarket_shopping_footer_font_size = get_theme_mod('supermarket_shopping_body_font_size');
    }

    $supermarket_shopping_footer_copyright_css = "
        .copy-right p {
            font-size: {$supermarket_shopping_footer_font_size}px;
            padding: {$supermarket_shopping_footer_padding}px;
        }
    ";
    wp_add_inline_style('supermarket-shopping-style', $supermarket_shopping_footer_copyright_css);

}

add_action(
    'wp_enqueue_scripts',
    'supermarket_shopping_enqueue_custom_css'
);


// Hook the function to the 'wp_enqueue_scripts' action
add_action('wp_enqueue_scripts', 'supermarket_shopping_enqueue_custom_css');