<?php

function eminent_posts_category(){
  $args = array('parent' => 0);
  $categories = get_categories($args);
  $category = array();
  $i = 0;
  foreach($categories as $categorys){
      if($i==0){
          $default = $categorys->slug;
          $i++;
      }
      $category[$categorys->term_id] = $categorys->name;
  }
  return $category;
}

function eminent_theme_customizer( $wp_customize ) {
	$wp_customize->add_panel(
    'general',
    array(
        'title' => __( 'General', 'eminent' ),
        'description' => __('styling options','eminent'),
        'priority' => 20, 
    )  );
	$wp_customize->get_section('title_tagline')->panel = 'general';
	$wp_customize->get_section('static_front_page')->panel = 'general';
    $wp_customize->get_section('header_image')->panel = 'general';
    $wp_customize->get_section('title_tagline')->title = __('Header & Logo','eminent');
    /* sections */
    $wp_customize->add_section( 'eminent_basic_section' , array(
    'title'       => __( 'Basic Settings', 'eminent' ),
    'priority'    => 30,
    'panel' =>'general'
	) );
	$wp_customize->add_panel( 'home_id', array(
		'capability'     => 'edit_theme_options',
		'theme_supports' => '',
		'title'          => __('Front Page Settings','eminent'),
		'description'    => '',
		'priority'    => 30,
	) );
    $wp_customize->add_section( 'eminent_silder_section' , array(
		'title'       => __( 'Slider Section', 'eminent' ),
		'priority'    => 30,
		'panel'  => 'home_id',
	) );
	$wp_customize->add_section( 'eminent_welcome_section' , array(
		'title'       => __( 'Welcome Section', 'eminent' ),
		'priority'    => 30,
		'panel'  => 'home_id',
	) );
    $wp_customize->add_section( 'eminent_blog_section' , array(
		'title'       => __( 'Blog Section', 'eminent' ),
		'priority'    => 30,
		'panel'  => 'home_id',
	) );
	$wp_customize->add_section( 'eminent_social_icons_section', array(
		'title'          => __('Top Header Social Settings','eminent'),
		'priority'       => 35,
		'panel' =>'general'
	) );
	$wp_customize->add_section( 'eminent_contact_section', array(
		'title'          => __('Contact Us Setting','eminent'),
		'priority'       => 35,
		'panel' =>'general'
	) );
	/* basic section */
	
	$wp_customize->add_setting( 'eminent_blogtitle', array(
        'default'        => ' ',
        'sanitize_callback' => 'esc_html',
    ) );
    $wp_customize->add_control( 'eminent_blogtitle', array(
	'label'   => __('Blog Title','eminent'),
	'section' => 'eminent_basic_section',
	'type'    => 'text',
    ) );
	$wp_customize->add_setting( 'copyright_url_setting', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
	$wp_customize->add_control( 'copyright_url_setting', array(
		'label'   => __('Copyright text','eminent'),
		'section' => 'eminent_basic_section',
		'type'    => 'text'
	) );
	/*$wp_customize->add_setting( 'eminent-breadcrumbsbg-bg' ,array(
		'sanitize_callback' => 'esc_url_raw',
		)
	 );
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'eminent-breadcrumbsbg-bg', array(
		'label'    => __( 'Breadcrumb ', 'eminent' ),
		'section'  => 'eminent_basic_section',
		'settings' => 'eminent-breadcrumbsbg-bg',	
	) ) );*/
	//welcome  Settings
	$wp_customize->add_setting( 'eminent_welcometitle', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
    $wp_customize->add_control( 'eminent_welcometitle', array(
		'label'   => __('Welcome Title','eminent'),
		'section' => 'eminent_welcome_section',
		'type'    => 'text',
    ) );
    $wp_customize->add_setting( 'eminent_welcome_subtitle', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
    $wp_customize->add_control( 'eminent_welcome_subtitle', array(
		'label'   => __('Welcome Subtitle','eminent'),
		'section' => 'eminent_welcome_section',
		'type'    => 'text',
    ) );
	 $wp_customize->add_setting( 'eminent_welcomeinfo', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
    $wp_customize->add_control( 'eminent_welcomeinfo', array(
		'label'   => __('Welcome Info','eminent'),
        'section' => 'eminent_welcome_section',
        'type'    => 'textarea',
           
    ) );
	$wp_customize->add_setting( 'eminent_welcome_image',array(
		'sanitize_callback' => 'esc_url_raw',
		)
	);
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'eminent_welcome_image', array(
			'label'    => __( 'Background Image (Recommended size 1280 x 853)', 'eminent' ),
			'section'  => 'eminent_welcome_section',
			'settings' => 'eminent_welcome_image',
		) 
	) );
	//Blog Section
	$wp_customize->add_setting( 'eminent_blog-title', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
    $wp_customize->add_control( 'eminent_blog-title', array(
		'label'   => __('Blog Title','eminent'),
        'section' => 'eminent_blog_section',
        'type'    => 'text'
    ) );
	$wp_customize->add_setting( 'eminent_bloginfo', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
    $wp_customize->add_control( 'eminent_bloginfo', array(
		'label'   => __('Blog Info','eminent'),
        'section' => 'eminent_blog_section',
        'type'    => 'textarea',
    ) );	
	
	 $wp_customize->add_setting( 'eminent_blogcategory', array(
		'default'        => 'uncategory',
		'sanitize_callback' => 'esc_html',
				
	) );
    $wp_customize->add_control( 'eminent_blogcategory', array(
		'label'   => __('Select Category','eminent'),
        'section' => 'eminent_blog_section',
        'type'    => 'select',
        'choices' => eminent_posts_category(),
    ) );

    //Front Page slider	
 	for($i=1;$i <= 4;$i++):  
	    $wp_customize->add_setting(
	        'eminent_homepage_sliderimage'.$i.'_image',
	        array(
	            'default' => '',
	            'capability'     => 'edit_theme_options',
	            'sanitize_callback' => 'absint',
	        ) );
	    $wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'eminent_homepage_sliderimage'.$i.'_image', array(
	        'section'     => 'eminent_silder_section',
	        'label'       => __( 'Upload Slider Image ' ,'eminent').$i,
	        'flex_width'  => true,
	        'flex_height' => true,
	        'width'       => 1350,
	        'height'      => 550,   
	        'default-image' => '',
	    ) ) );

	    $wp_customize->add_setting( 'eminent_homepage_sliderimage'.$i.'_title',
	        array(
	          'default' => '',
	            'capability'     => 'edit_theme_options',
	            'sanitize_callback' => 'sanitize_text_field',
	            'priority' => 20, 
	        ) );
	    $wp_customize->add_control( 'eminent_homepage_sliderimage'.$i.'_title',
	        array(            
	            'section' => 'eminent_silder_section',                
	            'label'   => __('Enter Slider Title ','eminent').$i,
	            'type'    => 'text',
	            'input_attrs' => array( 'placeholder' => esc_html__('Enter Slider Title','eminent')),
	        ) ); 
	    $wp_customize->add_setting( 'eminent_homepage_sliderimage'.$i.'_subtitle',
	        array(
	          'default' => '',
	            'capability'     => 'edit_theme_options',
	            'sanitize_callback' => 'wp_kses_post',
	            'priority' => 20, 
	        ) );
	    $wp_customize->add_control( 'eminent_homepage_sliderimage'.$i.'_subtitle',
	        array(            
	            'section' => 'eminent_silder_section',                
	            'label'   => __('Enter Slider Description ','eminent').$i,
	            'type'    => 'textarea',
	            'input_attrs' => array( 'placeholder' => esc_html__('Enter Slider Description','eminent')),
	        ) );        
	    $wp_customize->add_setting( 'eminent_homepage_sliderimage'.$i.'_link',
	        array(
	            'default' => '',
	            'capability'     => 'edit_theme_options',
	            'sanitize_callback' => 'esc_url_raw',
	            'priority' => 20, 
	        ) );
	    $wp_customize->add_control( 'eminent_homepage_sliderimage'.$i.'_link',
	        array(
	            'section' => 'eminent_silder_section',                
	            'label'   => __('Enter Slider Link ','eminent').$i,
	            'type'    => 'text',
	            'input_attrs' => array( 'placeholder' => esc_html__('Enter Slider URL','eminent')),
	        ) );
 	endfor;

	 // Contact Section
	$wp_customize->add_setting( 'contact_telephone_setting', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
	$wp_customize->add_control( 'contact_telephone_setting', array(
		'label'   => __('Contact Telephone','eminent'),
		'section' => 'eminent_contact_section',
		'type'    => 'text'
	) );
	$wp_customize->add_setting( 'contact_email_setting', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html'
	) );
	$wp_customize->add_control( 'contact_email_setting', array(
		'label'   => __('Contact Email','eminent'),
		'section' => 'eminent_contact_section',
		'type'    => 'text'
	) );
	// Social Section
	$wp_customize->add_setting( 'twitter_setting', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
	$wp_customize->add_control( 'twitter_setting', array(
		'label'   => __('Twitter URL','eminent'),
		'section' => 'eminent_social_icons_section',
		'type'    => 'text',
		'priority' => 1
	) );
	$wp_customize->add_setting( 'facebook_setting', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
	$wp_customize->add_control( 'facebook_setting', array(
		'label'   => __('Facebook URL','eminent'),
		'section' => 'eminent_social_icons_section',
		'type'    => 'text',
		'priority' => 1
	) );
	$wp_customize->add_setting( 'youtube_setting', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
	$wp_customize->add_control( 'youtube_setting', array(
		'label'   => __('YouTube URL','eminent'),
		'section' => 'eminent_social_icons_section',
		'type'    => 'text',
		'priority' => 1
	) );
	$wp_customize->add_setting( 'pinterest_setting', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
	$wp_customize->add_control( 'pinterest_setting', array(
		'label'   => __('Pinterest URL','eminent'),
		'section' => 'eminent_social_icons_section',
		'type'    => 'text',
		'priority' => 1
	) );
	$wp_customize->add_setting( 'rss_setting', array(
		'default'        => '',
		'sanitize_callback' => 'esc_html',
	) );
	$wp_customize->add_control( 'rss_setting', array(
		'label'   => __('RSS Feed URL','eminent'),
		'section' => 'eminent_social_icons_section',
		'type'    => 'text',
		'priority' => 1
	) );    
}
add_action( 'customize_register', 'eminent_theme_customizer' ); 

function eminent_custom_css()
{
	$custom_css='';
	$eminent_welcome_image=get_theme_mod('eminent_welcome_image');
	$eminent_header_bg_img=get_theme_mod('eminent-breadcrumbsbg-bg');
	if (!empty($eminent_welcome_image)){
		$eminent_welcome_image = esc_url(get_theme_mod('eminent_welcome_image'));
		$custom_css .=".welcome-section { background :url('".$eminent_welcome_image."');
		background-position: center;} ";
		
	}	

	wp_add_inline_style( 'eminent-style', $custom_css ); 
}