<?php
/**
 * Theme Options related to clients.
 *
 * @package Trade_Line
 */

$default = trade_line_get_default_theme_options();

// Add Panel.
$wp_customize->add_panel( 'theme_clients_panel',
	array(
	'title'      => __( 'Featured Clients', 'trade-line-pro' ),
	'priority'   => 100,
	'capability' => 'edit_theme_options',
	)
);

// Clients Type Section.
$wp_customize->add_section( 'section_theme_clients_type',
	array(
	'title'      => __( 'Clients Type', 'trade-line-pro' ),
	'priority'   => 100,
	'capability' => 'edit_theme_options',
	'panel'      => 'theme_clients_panel',
	)
);

// Setting featured_clients_status.
$wp_customize->add_setting( 'theme_options[featured_clients_status]',
	array(
	'default'           => $default['featured_clients_status'],
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'trade_line_sanitize_select',
	)
);
$wp_customize->add_control( 'theme_options[featured_clients_status]',
	array(
	'label'    => __( 'Enable Clients On', 'trade-line-pro' ),
	'section'  => 'section_theme_clients_type',
	'type'     => 'select',
	'priority' => 100,
	'choices'  => trade_line_get_featured_clients_content_options(),
	)
);

// Setting featured_clients_heading.
$wp_customize->add_setting( 'theme_options[featured_clients_heading]',
	array(
	'default'           => $default['featured_clients_heading'],
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'sanitize_text_field',
	)
);
$wp_customize->add_control( 'theme_options[featured_clients_heading]',
	array(
	'label'           => __( 'Heading Text', 'trade-line-pro' ),
	'section'         => 'section_theme_clients_type',
	'type'            => 'text',
	'priority'        => 100,
	'active_callback' => 'trade_line_is_featured_clients_active',
	)
);

// Setting featured_clients_number.
$wp_customize->add_setting( 'theme_options[featured_clients_number]',
	array(
	'default'           => $default['featured_clients_number'],
	'capability'        => 'edit_theme_options',
	'transport'         => 'postMessage',
	'sanitize_callback' => 'trade_line_sanitize_number_range',
	)
);
$wp_customize->add_control( 'theme_options[featured_clients_number]',
	array(
	'label'           => __( 'No of Clients', 'trade-line-pro' ),
	'description'     => __( 'Enter number between 1 and 20. Save and refresh the page if No of Clients is changed. ', 'trade-line-pro' ),
	'section'         => 'section_theme_clients_type',
	'type'            => 'number',
	'priority'        => 100,
	'input_attrs'     => array( 'min' => 1, 'max' => 20, 'step' => 1, 'style' => 'width: 55px;' ),
	'active_callback' => 'trade_line_is_featured_clients_active',
	)
);

$featured_clients_number = absint( trade_line_get_option( 'featured_clients_number' ) );

if ( $featured_clients_number > 0 ) {
	for ( $i = 1; $i <= $featured_clients_number; $i++ ) {
		$wp_customize->add_setting( "theme_options[featured_clients_logo_$i]",
			array(
			'default'           => isset( $default[ 'featured_clients_logo_' . $i ] ) ? $default[ 'featured_clients_logo_' .$i ] : '',
			'capability'        => 'edit_theme_options',
			'sanitize_callback' => 'trade_line_sanitize_image',
			)
		);

		$wp_customize->add_control(
			new WP_Customize_Image_Control( $wp_customize, "theme_options[featured_clients_logo_$i]",
				array(
					'label'           => __( 'Clients Logo', 'trade-line-pro' ) .' '.'#'. $i,
					'section'         => 'section_theme_clients_type',
					'settings'        => "theme_options[featured_clients_logo_$i]",
					'priority'        => 100,
					'active_callback' => 'trade_line_is_featured_clients_active',
				)
			)
		);
		$wp_customize->add_setting( "theme_options[featured_clients_url_$i]",
			array(
			'default'           => isset( $default[ 'featured_clients_url_' . $i ] ) ? $default[ 'featured_clients_url_' .$i ] : '',
			'capability'        => 'edit_theme_options',
			'sanitize_callback' => 'esc_url_raw',
			)
		);
		$wp_customize->add_control( "theme_options[featured_clients_url_$i]",
			array(
			'label'           => __( 'Clients URL', 'trade-line-pro' )  .' ' . '#' . $i,
			'section'         => 'section_theme_clients_type',
			'type'            => 'url',
			'priority'        => 100,
			'active_callback' => 'trade_line_is_featured_clients_active',
			)
		);
	} // End for loop.
}

// Clients Options Section.
$wp_customize->add_section( 'section_theme_clients_options',
	array(
	'title'      => __( 'Clients Options', 'trade-line-pro' ),
	'priority'   => 100,
	'capability' => 'edit_theme_options',
	'panel'      => 'theme_clients_panel',
	)
);

// Setting featured_clients_visible_active.
$wp_customize->add_setting( 'theme_options[featured_clients_visible_active]',
	array(
	'default'           => $default['featured_clients_visible_active'],
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'trade_line_sanitize_number_range',
	)
);

$wp_customize->add_control( 'theme_options[featured_clients_visible_active]',
	array(
	'label'       => __( 'Number of Visible Clients', 'trade-line-pro' ),
	'description' => __( 'Enter number between 5 and 10.', 'trade-line-pro' ),
	'section'     => 'section_theme_clients_options',
	'type'        => 'number',
	'priority'    => 100,
	'input_attrs' => array( 'min' => 5, 'max' => 10, 'step' => 1, 'style' => 'width: 55px;' ),
	)
);

// Setting featured_clients_transition_delay.
$wp_customize->add_setting( 'theme_options[featured_clients_transition_delay]',
	array(
	'default'           => $default['featured_clients_transition_delay'],
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'trade_line_sanitize_number_range',
	)
);
$wp_customize->add_control( 'theme_options[featured_clients_transition_delay]',
	array(
	'label'       => __( 'Transition Delay', 'trade-line-pro' ),
	'description' => __( 'in seconds', 'trade-line-pro' ),
	'section'     => 'section_theme_clients_options',
	'type'        => 'number',
	'priority'    => 100,
	'input_attrs' => array( 'min' => 1, 'max' => 10, 'step' => 1, 'style' => 'width: 55px;' ),
	)
);

// Setting featured_clients_enable_arrow.
$wp_customize->add_setting( 'theme_options[featured_clients_enable_arrow]',
	array(
	'default'           => $default['featured_clients_enable_arrow'],
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'trade_line_sanitize_checkbox',
	)
);
$wp_customize->add_control( 'theme_options[featured_clients_enable_arrow]',
	array(
	'label'    => __( 'Enable Arrow', 'trade-line-pro' ),
	'section'  => 'section_theme_clients_options',
	'type'     => 'checkbox',
	'priority' => 100,
	)
);

// Setting featured_clients_enable_autoplay.
$wp_customize->add_setting( 'theme_options[featured_clients_enable_autoplay]',
	array(
	'default'           => $default['featured_clients_enable_autoplay'],
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'trade_line_sanitize_checkbox',
	)
);
$wp_customize->add_control( 'theme_options[featured_clients_enable_autoplay]',
	array(
	'label'    => __( 'Enable Autoplay', 'trade-line-pro' ),
	'section'  => 'section_theme_clients_options',
	'type'     => 'checkbox',
	'priority' => 100,
	)
);

// Setting featured_clients_enable_non_circular.
$wp_customize->add_setting( 'theme_options[featured_clients_enable_non_circular]',
	array(
	'default'           => $default['featured_clients_enable_non_circular'],
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'trade_line_sanitize_checkbox',
	)
);
$wp_customize->add_control( 'theme_options[featured_clients_enable_non_circular]',
	array(
	'label'    => __( 'Enable Non Circlular Slide', 'trade-line-pro' ),
	'section'  => 'section_theme_clients_options',
	'type'     => 'checkbox',
	'priority' => 100,
	)
);

// Setting featured_clients_enable_new_window.
$wp_customize->add_setting( 'theme_options[featured_clients_enable_new_window]',
	array(
	'default'           => $default['featured_clients_enable_new_window'],
	'capability'        => 'edit_theme_options',
	'sanitize_callback' => 'trade_line_sanitize_checkbox',
	)
);
$wp_customize->add_control( 'theme_options[featured_clients_enable_new_window]',
	array(
	'label'    => __( 'Open Client URL in New Window', 'trade-line-pro' ),
	'section'  => 'section_theme_clients_options',
	'type'     => 'checkbox',
	'priority' => 100,
	)
);
