<?php
/**
 * ST Laundry Services Theme Customizer
 */

/**
 * Register customizer settings.
 */
function st_laundry_services_customize_register( $wp_customize ) {

	/* =========================================================
	   Loader Section
	========================================================= */
	$wp_customize->add_section( 'st_laundry_services_loader_section', array(
		'title'    => esc_html__( 'Loader Settings', 'st-laundry-services' ),
		'priority' => 30,
	) );

	// Setting: Loader Background Color
	$wp_customize->add_setting( 'st_laundry_services_loader_bg_color', array(
		'default'           => '#05173D',
		'sanitize_callback' => 'sanitize_hex_color',
		'transport'         => 'refresh',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control(
		$wp_customize,
		'st_laundry_services_loader_bg_color',
		array(
			'label'   => esc_html__( 'Loader Background Color', 'st-laundry-services' ),
			'section' => 'st_laundry_services_loader_section',
		)
	) );

	// Setting: Loader Image
	$wp_customize->add_setting( 'st_laundry_services_loader_image', array(
		'default'           => get_template_directory_uri() . '/assets/img/loader-logo.webp',
		'sanitize_callback' => 'esc_url_raw',
		'transport'         => 'refresh',
	) );

	$wp_customize->add_control( new WP_Customize_Image_Control(
		$wp_customize,
		'st_laundry_services_loader_image',
		array(
			'label'   => esc_html__( 'Loader Image', 'st-laundry-services' ),
			'section' => 'st_laundry_services_loader_section',
		)
	) );
}
add_action( 'customize_register', 'st_laundry_services_customize_register' );


/**
 * Output dynamic loader CSS based on customizer values.
 */
function st_laundry_services_loader_customizer_css() {
	$bg_color = get_theme_mod( 'st_laundry_services_loader_bg_color', '#05173D' );
	$bg_color = sanitize_hex_color( $bg_color );
	?>
	<style>
		#st-laundry-services-loader-container {
			background: <?php echo esc_attr( $bg_color ); ?>;
		}
	</style>
	<?php
}
add_action( 'wp_head', 'st_laundry_services_loader_customizer_css' );
