<?php
/**
 * Header Options.
 *
 * @package rubik_news
 */

// Header Options Panel.
$wp_customize->add_panel(
	'rubik_news_header_options_panel',
	array(
		'title'      => __( 'Header Options', 'rubik-news' ),
		'priority'   => 20,
		'capability' => 'edit_theme_options',
	)
);

$wp_customize->add_section(
	'rubik_news_top_bar_section',
	array(
		'title'    => __( 'Top Bar Options', 'rubik-news' ),
		'panel'    => 'rubik_news_header_options_panel',
		'priority' => 10,
	)
);

// Enable Top Bar.
$wp_customize->add_setting(
	'rubik_news_enable_top_bar',
	array(
		'default'           => true,
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'rubik_news_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	'rubik_news_enable_top_bar',
	array(
		'label'    => __( 'Enable Top Bar', 'rubik-news' ),
		'section'  => 'rubik_news_top_bar_section',
		'type'     => 'checkbox',
	)
);

// Show Current Date.
$wp_customize->add_setting(
	'rubik_news_show_header_date',
	array(
		'default'           => true,
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'rubik_news_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	'rubik_news_show_header_date',
	array(
		'label'    => __( 'Show Current Date', 'rubik-news' ),
		'section'  => 'rubik_news_top_bar_section',
		'type'     => 'checkbox',
	)
);

// Enable Social Icons.
$wp_customize->add_setting(
	'rubik_news_enable_header_social_icons',
	array(
		'default'           => true,
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'rubik_news_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	'rubik_news_enable_header_social_icons',
	array(
		'label'    => __( 'Enable Social Icons', 'rubik-news' ),
		'section'  => 'rubik_news_top_bar_section',
		'type'     => 'checkbox',
	)
);

// Location and Weather Text.
$wp_customize->add_setting(
	'rubik_news_header_weather_text',
	array(
		'default'           => __( 'New York • 22°C', 'rubik-news' ),
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'sanitize_text_field',
		'transport'         => 'refresh',
	)
);

$wp_customize->add_control(
	'rubik_news_header_weather_text',
	array(
		'label'       => __( 'Location and Weather Text', 'rubik-news' ),
		'description' => __( 'Example: New York • 22°C', 'rubik-news' ),
		'section'     => 'rubik_news_top_bar_section',
		'settings'    => 'rubik_news_header_weather_text',
		'type'        => 'text',
	)
);

// Follow Us Text.
$wp_customize->add_setting(
	'rubik_news_follow_us_text',
	array(
		'default'           => __( 'Follow Us:', 'rubik-news' ),
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'sanitize_text_field',
		'transport'         => 'refresh',
	)
);

$wp_customize->add_control(
	'rubik_news_follow_us_text',
	array(
		'label'       => __( 'Follow Us Text', 'rubik-news' ),
		'description' => __( 'Enter the text displayed before the social icons.', 'rubik-news' ),
		'section'     => 'rubik_news_top_bar_section',
		'settings'    => 'rubik_news_follow_us_text',
		'type'        => 'text',
	)
);

// Social URLs.
$social_links = array(
	'facebook' => array(
		'label'   => __( 'Facebook URL', 'rubik-news' ),
		'default' => 'https://www.facebook.com/',
	),
	'twitter' => array(
		'label'   => __( 'X / Twitter URL', 'rubik-news' ),
		'default' => 'https://x.com/',
	),
	'instagram' => array(
		'label'   => __( 'Instagram URL', 'rubik-news' ),
		'default' => 'https://www.instagram.com/',
	),
	'youtube' => array(
		'label'   => __( 'YouTube URL', 'rubik-news' ),
		'default' => 'https://www.youtube.com/',
	),
	'linkedin' => array(
		'label'   => __( 'LinkedIn URL', 'rubik-news' ),
		'default' => 'https://www.linkedin.com/',
	),
);

foreach ( $social_links as $social_id => $social_data ) {

	$wp_customize->add_setting(
		'rubik_news_' . $social_id . '_url',
		array(
			'default'           => $social_data['default'],
			'type'              => 'theme_mod',
			'capability'        => 'edit_theme_options',
			'sanitize_callback' => 'esc_url_raw',
		)
	);

	$wp_customize->add_control(
		'rubik_news_' . $social_id . '_url',
		array(
			'label'       => $social_data['label'],
			'section'     => 'rubik_news_top_bar_section',
			'type'        => 'url',
			'input_attrs' => array(
				'placeholder' => 'https://',
			),
		)
	);
}

$wp_customize->add_section(
	'rubik_news_header_advertisement_section',
	array(
		'title'    => __( 'Advertisement Options', 'rubik-news' ),
		'panel'    => 'rubik_news_header_options_panel',
		'priority' => 20,
	)
);

// Enable Advertisement.
$wp_customize->add_setting(
	'rubik_news_enable_header_advertisement',
	array(
		'default'           => true,
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'rubik_news_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	'rubik_news_enable_header_advertisement',
	array(
		'label'   => __( 'Enable Header Advertisement', 'rubik-news' ),
		'section' => 'rubik_news_header_advertisement_section',
		'type'    => 'checkbox',
	)
);

// Advertisement Image.
$wp_customize->add_setting(
	'rubik_news_header_advertisement_image',
	array(
		'default'           => 0,
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'absint',
	)
);

$wp_customize->add_control(
	new WP_Customize_Media_Control(
		$wp_customize,
		'rubik_news_header_advertisement_image',
		array(
			'label'       => __( 'Advertisement Image', 'rubik-news' ),
			'description' => __( 'Recommended size: 728 × 90 pixels.', 'rubik-news' ),
			'section'     => 'rubik_news_header_advertisement_section',
			'mime_type'   => 'image',
		)
	)
);

// Advertisement URL.
$wp_customize->add_setting(
	'rubik_news_header_advertisement_url',
	array(
		'default'           => '',
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'esc_url_raw',
	)
);

$wp_customize->add_control(
	'rubik_news_header_advertisement_url',
	array(
		'label'       => __( 'Advertisement Link', 'rubik-news' ),
		'section'     => 'rubik_news_header_advertisement_section',
		'type'        => 'url',
		'input_attrs' => array(
			'placeholder' => 'https://',
		),
	)
);

// Open Advertisement in New Tab.
$wp_customize->add_setting(
	'rubik_news_header_advertisement_new_tab',
	array(
		'default'           => true,
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'rubik_news_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	'rubik_news_header_advertisement_new_tab',
	array(
		'label'   => __( 'Open Advertisement in New Tab', 'rubik-news' ),
		'section' => 'rubik_news_header_advertisement_section',
		'type'    => 'checkbox',
	)
);

$wp_customize->add_section(
	'rubik_news_navigation_options_section',
	array(
		'title'    => __( 'Navigation Options', 'rubik-news' ),
		'panel'    => 'rubik_news_header_options_panel',
		'priority' => 30,
	)
);

// Enable Search.
$wp_customize->add_setting(
	'rubik_news_enable_header_search',
	array(
		'default'           => true,
		'type'              => 'theme_mod',
		'capability'        => 'edit_theme_options',
		'sanitize_callback' => 'rubik_news_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	'rubik_news_enable_header_search',
	array(
		'label'   => __( 'Enable Search Icon', 'rubik-news' ),
		'section' => 'rubik_news_navigation_options_section',
		'type'    => 'checkbox',
	)
);