<?php
/**
 * Recent Jobs Section options
 *
 * @package Theme Palace
 * @subpackage  Onjob
 * @since  Onjob 1.0.0
 */

// Add Recent Jobs section
$wp_customize->add_section( 'onjob_recent_job_section',
	array(
		'title'             => esc_html__( 'Recent Jobs','onjob' ),
        'description'	    => sprintf( esc_html__( '%1$sWP Job Manage%2$s should be installed and active for this section to work.', 'onjob' ), '<a target="_blank" href="'.admin_url('themes.php?page=tgmpa-install-plugins&plugin_status=install').'">', '</a>' ),
		'panel'             => 'onjob_front_page_panel',
	)
);

// Recent Jobs content enable control and setting
$wp_customize->add_setting( 'onjob_theme_options[recent_job_section_enable]',
	array(
		'default'			=> 	$options['recent_job_section_enable'],
		'sanitize_callback' => 'onjob_sanitize_switch_control',
	)
);

$wp_customize->add_control( new  Onjob_Switch_Control( $wp_customize,
	'onjob_theme_options[recent_job_section_enable]',
		array(
			'label'             => esc_html__( 'Recent Jobs Section Enable', 'onjob' ),
			'section'           => 'onjob_recent_job_section',
			'on_off_label' 		=> onjob_switch_options(),
		)
	)
);

// Recent Jobs section sub title control and setting
$wp_customize->add_setting('onjob_theme_options[recent_job_sub_title]',
    array(
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
        'default'           => $options['recent_job_sub_title'],
    )
);

$wp_customize->add_control('onjob_theme_options[recent_job_sub_title]',
    array(
        'label'             => esc_html__('Section Sub Title', 'onjob'),
        'section'           => 'onjob_recent_job_section',
        'type'              => 'text',
        'active_callback'   => 'onjob_is_recent_job_section_enable',
    )
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'onjob_theme_options[recent_job_sub_title]',
        array(
            'selector'            => '#recent-jobs .section-header p.section-subtitle',
            'settings'            => 'onjob_theme_options[recent_job_sub_title]',
            'container_inclusive' => false,
            'fallback_refresh'    => true,
            'render_callback'     => 'onjob_recent_job_sub_title_partial',
        )
    );
}

// blog title setting and control
$wp_customize->add_setting( 'onjob_theme_options[recent_job_title]',
    array(
        'sanitize_callback' => 'sanitize_text_field',
        'default'           => $options['blog_title'],
        'transport'         => 'postMessage',
    )
);

$wp_customize->add_control( 'onjob_theme_options[recent_job_title]',
    array(
        'label'             => esc_html__( 'Section Title', 'onjob' ),
        'section'           => 'onjob_recent_job_section',
        'active_callback'   => 'onjob_is_recent_job_section_enable',
        'type'              => 'text',
    ) 
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'onjob_theme_options[recent_job_title]',
        array(
            'selector'            => '#recent-jobs .section-header h2.section-title',
            'settings'            => 'onjob_theme_options[recent_job_title]',
            'container_inclusive' => false,
            'fallback_refresh'    => true,
            'render_callback'     => 'onjob_recent_job_title_partial',
        )
    );
}

for ( $i = 1; $i <= $options['recent_job_count']; $i++ ) :

	// recent_job hr setting and control
	$wp_customize->add_setting( 'onjob_theme_options[recent_job_hr_'. $i .']',
		array(
			'sanitize_callback' => 'onjob_sanitize_html'
		)
	);

	$wp_customize->add_control( new  Onjob_Customize_Horizontal_Line( $wp_customize,
		'onjob_theme_options[recent_job_hr_'. $i .']',
			array(
				'section'         => 'onjob_recent_job_section',
				'active_callback' => 'onjob_is_recent_job_section_enable',
				'type'			  => 'hr'
			)
		)
	);
	
	// recent_job posts drop down chooser control and setting
	$wp_customize->add_setting( 'onjob_theme_options[recent_job_content_job_' . $i . ']',
		array(
			'sanitize_callback' => 'onjob_sanitize_page',
		)
	);

	$wp_customize->add_control( new  Onjob_Dropdown_Chooser( $wp_customize,
		'onjob_theme_options[recent_job_content_job_' . $i . ']',
			array(
				'label'             => sprintf( esc_html__( 'Select Job %d', 'onjob' ), $i ),
				'section'           => 'onjob_recent_job_section',
				'choices'			=> onjob_job_listing_choices(),
				'active_callback'	=> 'onjob_is_recent_job_section_enable',
			)
		)
	);
endfor;
