<?php
/**
 * Header Customizer controls.
 *
 * @package ttsunsolar
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Register header settings.
 *
 * @param WP_Customize_Manager $wp_customize Customizer.
 */
function ttsunsolar_customizer_header( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport        = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';

	$wp_customize->add_setting(
		'ttsunsolar_show_tagline_with_logo',
		array(
			'default'           => true,
			'sanitize_callback' => 'ttsunsolar_sanitize_checkbox',
			'transport'         => 'refresh',
		)
	);
	$wp_customize->add_control(
		'ttsunsolar_show_tagline_with_logo',
		array(
			'label'       => esc_html__( 'Show tagline with logo', 'ttsunsolar' ),
			'description' => esc_html__( 'When a custom logo is uploaded, also display the site tagline below it.', 'ttsunsolar' ),
			'section'     => 'title_tagline',
			'type'        => 'checkbox',
			'priority'    => 50,
		)
	);

	$wp_customize->add_section(
		'ttsunsolar_header',
		array(
			'title'       => esc_html__( 'Header', 'ttsunsolar' ),
			'description' => esc_html__( 'Top bar contact + social links. Site title/tagline use Site Identity (defaults: TTSun Solar / Clean Energy Solutions).', 'ttsunsolar' ),
			'panel'       => 'ttsunsolar_panel',
			'priority'    => 10,
		)
	);

	$fields = array(
		'ttsunsolar_phone'   => array( 'label' => __( 'Phone Number', 'ttsunsolar' ), 'default' => '11111111111', 'sanitize' => 'ttsunsolar_sanitize_phone' ),
		'ttsunsolar_email'   => array( 'label' => __( 'Email', 'ttsunsolar' ), 'default' => 'info@example.com', 'sanitize' => 'sanitize_email' ),
		'ttsunsolar_address' => array( 'label' => __( 'Address (top bar)', 'ttsunsolar' ), 'default' => '123 Lorem Ipsum Street', 'sanitize' => 'sanitize_text_field' ),
		'ttsunsolar_facebook'  => array( 'label' => __( 'Facebook URL', 'ttsunsolar' ), 'default' => 'https://www.facebook.com/', 'sanitize' => 'esc_url_raw' ),
		'ttsunsolar_twitter'   => array( 'label' => __( 'Twitter / X URL', 'ttsunsolar' ), 'default' => 'https://twitter.com/', 'sanitize' => 'esc_url_raw' ),
		'ttsunsolar_linkedin'  => array( 'label' => __( 'LinkedIn URL', 'ttsunsolar' ), 'default' => 'https://www.linkedin.com/', 'sanitize' => 'esc_url_raw' ),
		'ttsunsolar_pinterest' => array( 'label' => __( 'Pinterest URL', 'ttsunsolar' ), 'default' => 'https://www.pinterest.com/', 'sanitize' => 'esc_url_raw' ),
		'ttsunsolar_instagram' => array( 'label' => __( 'Instagram URL', 'ttsunsolar' ), 'default' => 'https://www.instagram.com/', 'sanitize' => 'esc_url_raw' ),
	);

	foreach ( $fields as $id => $args ) {
		$wp_customize->add_setting(
			$id,
			array(
				'default'           => $args['default'],
				'sanitize_callback' => $args['sanitize'],
			)
		);
		$wp_customize->add_control(
			$id,
			array(
				'label'   => esc_html( $args['label'] ),
				'section' => 'ttsunsolar_header',
				'type'    => 'text',
			)
		);
	}
}
