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

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

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

	// Setting: Loader Background Color
	$wp_customize->add_setting( 'st_carpenter_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_carpenter_loader_bg_color',
		array(
			'label'   => esc_html__( 'Loader Background Color', 'st-carpenter' ),
			'section' => 'st_carpenter_loader_section',
		)
	) );

	// Setting: Loader Image
	$wp_customize->add_setting( 'st_carpenter_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_carpenter_loader_image',
		array(
			'label'   => esc_html__( 'Loader Image', 'st-carpenter' ),
			'section' => 'st_carpenter_loader_section',
		)
	) );
}
add_action( 'customize_register', 'st_carpenter_customize_register' );


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