<?php
/**
 * ST Apostille Theme Customizer
 */

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

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

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

	$wp_customize->add_control( new WP_Customize_Color_Control(
		$wp_customize,
		'st_apostille_loader_bg_color',
		array(
			'label'   => esc_html__( 'Loader Background Color', 'st-apostille' ),
			'section' => 'st_apostille_loader_section',
		)
	) );

	// Setting: Loader Image
	$wp_customize->add_setting( 'st_apostille_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_apostille_loader_image',
		array(
			'label'   => esc_html__( 'Loader Image', 'st-apostille' ),
			'section' => 'st_apostille_loader_section',
		)
	) );
}
add_action( 'customize_register', 'st_apostille_customize_register' );


/**
 * Output dynamic loader CSS based on customizer values.
 */
function st_apostille_loader_customizer_css() {
	$bg_color = get_theme_mod( 'st_apostille_loader_bg_color', '#ffffff' );
	$bg_color = sanitize_hex_color( $bg_color );
	?>
	<style>
		#st-apostille-loader-container {
			background: <?php echo esc_attr( $bg_color ); ?>;
		}
	</style>
	<?php
}
add_action( 'wp_head', 'st_apostille_loader_customizer_css' );
