<?php

/**
 * Add Customizer Options for frontpage
 */

/**
 * Check for WP_Customizer_Control existence before adding custom control because WP_Customize_Control
 * is loaded on customizer page only
 *
 * @see _wp_customize_include()
 */
if ( class_exists( 'WP_Customize_Control' ) ) {
  get_template_part( '/inc/customizer/class-customizer-toggle' );
}

function prime_business_general_setup( $wp_customize ) {

    /******************************** Primary Color *****************************/
    $wp_customize->add_setting( 'prime_business_primary_color_setting', array(
      'default'   => '#43c6ac',
      'sanitize_callback' => 'sanitize_hex_color',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'prime_business_primary_color_control', array(
      'section'  => 'colors',
      'label'    => esc_html__( 'Primary Color', 'prime-business' ),
      'settings' =>  'prime_business_primary_color_setting',
    ) ) );

    /******************************** Secondary Color *****************************/
    $wp_customize->add_setting( 'prime_business_secondary_color_setting', array(
      'default'   => '#f6f163',
      'sanitize_callback' => 'sanitize_hex_color',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'prime_business_secondary_color_control', array(
      'section'  => 'colors',
      'label'    => esc_html__( 'Secondary Color', 'prime-business' ),
      'settings' =>  'prime_business_secondary_color_setting',
    ) ) );

    /******************************** Site Description Switch *****************************/
    $wp_customize->add_setting( 'prime_business_site_description_switch_setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-site-description-switch-control', array(
      'label'       => __( 'Enable Site Desctiption?', 'prime-business' ),
      'section'     => 'title_tagline',
      'settings'    => 'prime_business_site_description_switch_setting',
      'type'        => 'ios',
    ) ) );

/*****************************************************************************
 * Documentation and Help Section
 ******************************************************************************/
$wp_customize->add_section( 'prime-business-documentation-section', array(
  'title'       =>  __( 'Demo & Documentation', 'prime-business' ),
  'priority'    =>  1
) );

// Documentation Setting
$wp_customize->add_setting( 'prime-business-documentation-setting', array(
  'capability'        => 'edit_theme_options',
  'sanitize_callback' => 'absint',
) );

$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-documentation-hidden-description-control', array(
    /* Translators: %s: Documentation Link */
    'description'    => sprintf( __( 'Read our full setup documentation: %1$sclick here%2$s', 'prime-business' ), '<a href="' . esc_url( 'https://www.crafthemes.com/docs/prime-business-documentation/' ) . '" target="_blank">', '</a>' ),
    'section'         => 'prime-business-documentation-section',
    'settings'        => 'prime-business-documentation-setting',
    'type'            => 'hidden',
  ) ) );

$wp_customize->add_setting( 'prime-business-documentation-demo-setting', array(
  'capability'        => 'edit_theme_options',
  'sanitize_callback' => 'absint',
) );

$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-documentation-hidden-demo-control', array(
    /* Translators: %s: Demo link */
    'description'    => sprintf( __( 'Theme Demo: %1$sclick here%2$s', 'prime-business' ), '<a href="' . esc_url( 'https://www.crafthemes-demo.com/prime-business/' ) . '" target="_blank">', '</a>' ),
    'section'         => 'prime-business-documentation-section',
    'settings'        => 'prime-business-documentation-demo-setting',
    'type'            => 'hidden',
  ) ) );

 /*****************************************************************************
 * Topbar Section
 ******************************************************************************/
  $wp_customize->add_section( 'prime-business-topbar-section', array(
    'title'       =>  __( 'Topbar Setup', 'prime-business' ),
    'priority'    =>  1
  ) );

  // TopBar Switch
  $wp_customize->add_setting( 'prime-business-topbar-switch-setting', array(
    'capability'        => 'edit_theme_options',
    'sanitize_callback' => 'absint',
    'default'           => false
  ) );

  $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-topbar-switch-control', array(
    'label'       => __( 'Enable Topbar?', 'prime-business' ),
    'section'     => 'prime-business-topbar-section',
    'settings'    => 'prime-business-topbar-switch-setting',
    'type'        => 'ios',
  ) ) );

  $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-introduction-hidden-description-control', array(
      'description'    => __( 'Goto Widgets section and add widgets for topbar contents. For Social Media links, goto Menus and create a menu and add your social media links and set the menu location as Social Menu.', 'prime-business' ),
      'section'         => 'prime-business-topbar-section',
      'settings'        => 'prime-business-topbar-switch-setting',
      'type'            => 'hidden',
      'active_callback' => 'prime_business_flag_is_topbar_diabled',
    ) ) );
}

add_action( 'customize_register', 'prime_business_general_setup' );

function prime_business_homepage_setup( $wp_customize ) {

/*******************************************************************************
 * Homepage Slider
 ******************************************************************************/

    // Add Panel Front Page
    $wp_customize->add_panel( 'prime-business-frontpage', array(
        'priority'       => 10,
        'capability'     => 'edit_theme_options',
        'title'          => __( 'Front Page Setup', 'prime-business' ),
        'description'    => '',
    ) );

    $wp_customize->add_section( 'prime-business-slider-section', array(
      'title'       =>  __( 'Front Page Slider', 'prime-business' ),
      'priority'    =>  10,
      'panel'       =>  'prime-business-frontpage'
    ) );

    // Slider Switch
    $wp_customize->add_setting( 'prime-business-slider-switch-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-slider-switch-control', array(
      'label'       => __( 'Enable Slider?', 'prime-business' ),
      'section'     => 'prime-business-slider-section',
      'settings'    => 'prime-business-slider-switch-setting',
      'type'        => 'ios',
    ) ) );

    for ( $prime_business_count = 1; $prime_business_count < 5; $prime_business_count++ ) {
        // Call Slider pages
        $wp_customize->add_setting( "prime-business-slider-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'absint'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-slider-control-$prime_business_count", array(
          /* Translators: %s: Page number */
          'label'           => sprintf( __( 'Select Slider Page %s', 'prime-business' ), $prime_business_count ),
          'description' =>  __( 'Select from your existing pages for slider title. Add featured image to the selected pages for slider background.', 'prime-business' ),
          'section'         => 'prime-business-slider-section',
          'settings'        => "prime-business-slider-setting-$prime_business_count",
          'type'            => 'dropdown-pages',
          'active_callback' => 'prime_business_flag_is_slider_diabled',
        ) ) );

        // Excerpt Switch
        $wp_customize->add_setting( "prime-business-slider-excerpt-switch-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'absint',
          'default'           => false
        ) );

        $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, "prime-business-slider-excerpt-switch-control-$prime_business_count", array(
          'label'           => __( 'Enable Excerpt?', 'prime-business' ),
          /* Translators: %s: Tutorial url */
          'description'     => sprintf( __( '%1$sHow to add custom excerpt?%2$s', 'prime-business' ), '<a href="' . esc_url( 'https://wp.me/p8PjEW-li' ) . '" target="_blank">', '</a>' ),
          'section'         => 'prime-business-slider-section',
          'settings'        => "prime-business-slider-excerpt-switch-setting-$prime_business_count",
          'type'            => 'ios',
          'active_callback' => 'prime_business_flag_is_slider_diabled',
        ) ) );

        // Button 1 text and url - Text Field
        $wp_customize->add_setting( "prime-business-slider-button1-text-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'sanitize_text_field'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-slider-button1-text-control-$prime_business_count", array(
          'label'           => __( 'First button Title', 'prime-business' ),
          'section'         => 'prime-business-slider-section',
          'settings'        => "prime-business-slider-button1-text-setting-$prime_business_count",
          'type'            => 'text',
          'active_callback' => 'prime_business_flag_is_slider_diabled',
        ) ) );

        $wp_customize->add_setting( "prime-business-slider-button1-url-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'sanitize_text_field'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-slider-button1-url-control-$prime_business_count", array(
          'label'           => __( 'First button link', 'prime-business' ),
          'section'         => 'prime-business-slider-section',
          'settings'        => "prime-business-slider-button1-url-setting-$prime_business_count",
          'type'            => 'text',
          'active_callback' => 'prime_business_flag_is_slider_diabled',
        ) ) );

        // Button 2 text and url - Text Field
        $wp_customize->add_setting( "prime-business-slider-button2-text-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'sanitize_text_field'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-slider-button2-text-control-$prime_business_count", array(
          'label'           => __( 'Second button Title', 'prime-business' ),
          'section'         => 'prime-business-slider-section',
          'settings'        => "prime-business-slider-button2-text-setting-$prime_business_count",
          'type'            => 'text',
          'active_callback' => 'prime_business_flag_is_slider_diabled',
        ) ) );

        $wp_customize->add_setting( "prime-business-slider-button2-url-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'sanitize_text_field'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-slider-button2-url-control-$prime_business_count", array(
          'label'           => __( 'Second button link', 'prime-business' ),
          'section'         => 'prime-business-slider-section',
          'settings'        => "prime-business-slider-button2-url-setting-$prime_business_count",
          'type'            => 'text',
          'active_callback' => 'prime_business_flag_is_slider_diabled',
        ) ) );

        $wp_customize->selective_refresh->add_partial( "prime-business-slider-partial-$prime_business_count", array(
            'selector'            => ".slider-content-$prime_business_count",
            'container_inclusive' => true,
            'settings'            => "prime-business-slider-setting-$prime_business_count",
        ) );
    }

     // Slider Settings Headline
      $wp_customize->add_setting( 'prime-business-slider-options-headline-setting', array(
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'absint',
      ) );

      $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, "prime-business-slider-options-headline-control", array(
        'label'           => __( 'Slider Settings', 'prime-business' ),
        'section'         => 'prime-business-slider-section',
        'settings'        => "prime-business-slider-options-headline-setting",
        'type'            => 'hidden',
        'active_callback' => 'prime_business_flag_is_slider_diabled',
      ) ) );

    for ( $prime_business_count = 0; $prime_business_count < 4; $prime_business_count++ ) {

      $prime_business_individual_option = array(
        __( 'Enable Carousel Dots?', 'prime-business' ),
        __( 'Enable Arrows?', 'prime-business' ),
        __( 'Enable Fade Effect?', 'prime-business' ),
        __( 'Enable Autoplay?', 'prime-business' ),
      );

      // Slider Settings
      $wp_customize->add_setting( "prime-business-slider-options-setting-$prime_business_count", array(
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'absint',
        'default'           => true
      ) );

      $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, "prime-business-slider-options-control-$prime_business_count", array(
        /* Translators: %s: Field Titles */
        'label'           => sprintf( '%s' , $prime_business_individual_option[ $prime_business_count ] ),
        'section'         => 'prime-business-slider-section',
        'settings'        => "prime-business-slider-options-setting-$prime_business_count",
        'type'            => 'ios',
        'active_callback' => 'prime_business_flag_is_slider_diabled',
      ) ) );
    }

/*******************************************************************************
 * Homepage Introduction Section
 ******************************************************************************/

    $wp_customize->add_section( 'prime-business-introduction-section', array(
      'title'       =>  __( 'Introduction', 'prime-business' ),
      'priority'    =>  10,
      'panel'       =>  'prime-business-frontpage'
    ) );

    // Introduction Switch
    $wp_customize->add_setting( 'prime-business-introduction-switch-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-introduction-switch-control', array(
      'label'       => __( 'Enable Introduction?', 'prime-business' ),
      'section'     => 'prime-business-introduction-section',
      'settings'    => 'prime-business-introduction-switch-setting',
      'type'        => 'ios',
    ) ) );

    // Introduction Subtitle - Text Field
    $wp_customize->add_setting( 'prime-business-introduction-subtitle-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'sanitize_text_field'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-introduction-subtitle-control', array(
      'label'           => __( 'Introduction Subtitle', 'prime-business' ),
      'section'         => 'prime-business-introduction-section',
      'settings'        => 'prime-business-introduction-subtitle-setting',
      'type'            => 'text',
      'active_callback' => 'prime_business_flag_is_introduction_diabled',
    ) ) );

    $wp_customize->selective_refresh->add_partial( "prime-business-introduction-subtitle-partial", array(
        'selector'            => ".introduction-subtitle",
        'container_inclusive' => true,
        'settings'            => "prime-business-introduction-subtitle-setting",
    ) );

    // Call Introduction page
    $wp_customize->add_setting( 'prime-business-introduction-page-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-introduction-page-control', array(
      'label'           => __( 'Introduction Content', 'prime-business' ),
      'description'     =>  __( 'Select from your existing pages for introduction content. Add Featured image to the page for the display image.', 'prime-business' ),
      'section'         => 'prime-business-introduction-section',
      'settings'        => 'prime-business-introduction-page-setting',
      'type'            => 'dropdown-pages',
      'active_callback' => 'prime_business_flag_is_introduction_diabled',
    ) ) );

    $wp_customize->selective_refresh->add_partial( "prime-business-introduction-page-partial", array(
        'selector'            => ".introduction-content",
        'container_inclusive' => true,
        'settings'            => "prime-business-introduction-page-setting",
    ) );

    // Read more Switch
    $wp_customize->add_setting( 'prime-business-introduction-readmore-switch-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, "prime-business-introduction-readmore-switch-control", array(
      'label'       => __( 'Enable Read more link?', 'prime-business' ),
      'section'     => 'prime-business-introduction-section',
      'settings'    => "prime-business-introduction-readmore-switch-setting",
      'type'        => 'ios',
      'active_callback' => 'prime_business_flag_is_introduction_diabled',
    ) ) );

    // Read More - Text Field
    $wp_customize->add_setting( 'prime-business-introduction-readmore-text-setting', array(
      'capability'        => 'edit_theme_options',
      'default'         => __( 'Read More', 'prime-business' ),
      'sanitize_callback' => 'sanitize_text_field'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-introduction-readmore-text-control', array(
      'label'           => __( 'Read More Text', 'prime-business' ),
      'section'         => 'prime-business-introduction-section',
      'settings'        => 'prime-business-introduction-readmore-text-setting',
      'type'            => 'text',
      'active_callback' => 'prime_business_flag_is_introduction_readmore_diabled',
    ) ) );

    /******************************** Introduction Background Color *****************************/
    $wp_customize->add_setting( 'prime_business_introduction_background_color_setting', array(
      'default'   => '#fff',
      'sanitize_callback' => 'sanitize_hex_color',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'prime_business_introduction_background_color_control', array(
      'section'  => 'prime-business-introduction-section',
      'label'    => esc_html__( 'Background Color', 'prime-business' ),
      'settings' => 'prime_business_introduction_background_color_setting',
      'active_callback' => 'prime_business_flag_is_introduction_diabled',
    ) ) );

/*******************************************************************************
 * Homepage Services Section
 ******************************************************************************/

    $wp_customize->add_section( 'prime-business-services-section', array(
      'title'       =>  __( 'Services', 'prime-business' ),
      'priority'    =>  10,
      'panel'       =>  'prime-business-frontpage'
    ) );

    // Services Switch
    $wp_customize->add_setting( 'prime-business-services-switch-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-services-switch-control', array(
      'label'       => __( 'Enable Services?', 'prime-business' ),
      'section'     => 'prime-business-services-section',
      'settings'    => 'prime-business-services-switch-setting',
      'type'        => 'ios',
    ) ) );

    // Services Subtitle - Text Field
    $wp_customize->add_setting( 'prime-business-services-subtitle-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'sanitize_text_field'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-services-subtitle-control', array(
      'label'           => __( 'Services Subtitle', 'prime-business' ),
      'section'         => 'prime-business-services-section',
      'settings'        => 'prime-business-services-subtitle-setting',
      'type'            => 'text',
      'active_callback' => 'prime_business_flag_is_services_diabled',
    ) ) );

    $wp_customize->selective_refresh->add_partial( 'prime-business-services-subtitle-partial', array(
        'selector'            => '.services-subtitle',
        'container_inclusive' => true,
        'settings'            => 'prime-business-services-subtitle-setting',
    ) );

    // Call Services page
    $wp_customize->add_setting( 'prime-business-services-page-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-services-page-control', array(
      'label'           => __( 'Services Title Content', 'prime-business' ),
      'description'     =>  __( 'Select from your existing pages for Services title content.', 'prime-business' ),
      'section'         => 'prime-business-services-section',
      'settings'        => 'prime-business-services-page-setting',
      'type'            => 'dropdown-pages',
      'active_callback' => 'prime_business_flag_is_services_diabled',
    ) ) );

    $wp_customize->selective_refresh->add_partial( 'prime-business-services-page-partial', array(
        'selector'            => '.services-title',
        'container_inclusive' => true,
        'settings'            => 'prime-business-services-page-setting',
    ) );


    for ( $prime_business_count = 1; $prime_business_count < 7; $prime_business_count++ ) {

        // Features Icon - Text Field
        $wp_customize->add_setting( "prime-business-service-icon-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'sanitize_text_field',
          'default'           =>  'fa-line-chart'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-service-icon-control-$prime_business_count", array(
          /* Translators: %s: Icon numbers */
          'label'           => sprintf( __( 'Feature Icon %s', 'prime-business' ), $prime_business_count ),
          /* Translators: %s: Font Awesome url */
          'description'     => sprintf( __( 'Please input icon as eg: fa-star. Find Font-awesome icons %1$shere%2$s', 'prime-business' ), '<a href="' . esc_url( 'https://fontawesome.com/v4.7.0/cheatsheet/' ) . '" target="_blank">', '</a>' ),
          'section'         => 'prime-business-services-section',
          'settings'        => "prime-business-service-icon-setting-$prime_business_count",
          'type'            => 'text',
          'active_callback' => 'prime_business_flag_is_services_diabled',
        ) ) );

        // Call Service pages
        $wp_customize->add_setting( "prime-business-service-content-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'absint'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-service-content-control-$prime_business_count", array(
          /* Translators: %s: Service numbers */
          'label'           => sprintf( __( 'Select Service %s', 'prime-business' ), $prime_business_count ),
          'description'     => __( 'Select from your existing pages for service content.', 'prime-business' ),
          'section'         => 'prime-business-services-section',
          'settings'        => "prime-business-service-content-setting-$prime_business_count",
          'type'            => 'dropdown-pages',
          'active_callback' => 'prime_business_flag_is_services_diabled',
        ) ) );

        $wp_customize->selective_refresh->add_partial( "prime-business-services-page-partial-$prime_business_count", array(
            'selector'            => ".service-content-$prime_business_count",
            'container_inclusive' => true,
            'settings'            => "prime-business-service-content-setting-$prime_business_count",
        ) );

        // Read more Switch
        $wp_customize->add_setting( "prime-business-services-readmore-switch-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'absint',
          'default'           => false
        ) );

        $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, "prime-business-services-readmore-switch-control-$prime_business_count", array(
          'label'       => __( 'Enable Read more link?', 'prime-business' ),
          'section'     => 'prime-business-services-section',
          'settings'    => "prime-business-services-readmore-switch-setting-$prime_business_count",
          'type'        => 'ios',
          'active_callback' => 'prime_business_flag_is_services_diabled',
        ) ) );

        // Read More - Text Field
        $wp_customize->add_setting( "prime-business-services-readmore-text-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'default'         => __( 'Read More', 'prime-business' ),
          'sanitize_callback' => 'sanitize_text_field'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-services-readmore-text-control-$prime_business_count", array(
          'label'           => __( 'Read More Text', 'prime-business' ),
          'section'         => 'prime-business-services-section',
          'settings'        => "prime-business-services-readmore-text-setting-$prime_business_count",
          'type'            => 'text',
          'active_callback' => 'prime_business_flag_is_services_diabled',
        ) ) );
    }

    /******************************** Services Background Color *****************************/
    $wp_customize->add_setting( 'prime_business_services_background_color_setting', array(
      'default'   => '#fff',
      'sanitize_callback' => 'sanitize_hex_color',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'prime_business_services_background_color_control', array(
      'section'  => 'prime-business-services-section',
      'label'    => esc_html__( 'Background Color', 'prime-business' ),
      'settings' => 'prime_business_services_background_color_setting',
      'active_callback' => 'prime_business_flag_is_services_diabled',
    ) ) );


/*******************************************************************************
 * Homepage Team Members Section
 ******************************************************************************/

    $wp_customize->add_section( 'prime-business-team-section', array(
      'title'       =>  __( 'Team Members', 'prime-business' ),
      'priority'    =>  10,
      'panel'       =>  'prime-business-frontpage'
    ) );

    // Team Members Switch
    $wp_customize->add_setting( 'prime-business-team-switch-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-members-switch-control', array(
      'label'       => __( 'Enable Team Members?', 'prime-business' ),
      'section'     => 'prime-business-team-section',
      'settings'    => 'prime-business-team-switch-setting',
      'type'        => 'ios',
    ) ) );

    // Team Members Subtitle - Text Field
    $wp_customize->add_setting( 'prime-business-team-subtitle-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'sanitize_text_field'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-team-subtitle-control', array(
      'label'           => __( 'Team Members Subtitle', 'prime-business' ),
      'section'         => 'prime-business-team-section',
      'settings'        => 'prime-business-team-subtitle-setting',
      'type'            => 'text',
      'active_callback' => 'prime_business_flag_is_team_members_diabled',
    ) ) );

    $wp_customize->selective_refresh->add_partial( "prime-business-team-subtitle-partial", array(
        'selector'            => ".team-members-subtitle",
        'container_inclusive' => true,
        'settings'            => "prime-business-team-subtitle-setting",
    ) );

    // Call Team Members page
    $wp_customize->add_setting( 'prime-business-team-page-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-team-page-control', array(
      'label'           => __( 'Title and Description', 'prime-business' ),
      'description'     =>  __( 'Select from your existing pages for title and description content', 'prime-business' ),
      'section'         => 'prime-business-team-section',
      'settings'        => 'prime-business-team-page-setting',
      'type'            => 'dropdown-pages',
      'active_callback' => 'prime_business_flag_is_team_members_diabled',
    ) ) );

    $wp_customize->selective_refresh->add_partial( "prime-business-team-title-partial", array(
        'selector'            => ".team-members-title",
        'container_inclusive' => true,
        'settings'            => "prime-business-team-page-setting",
    ) );

    // Team Members Columns - Number Field
    $wp_customize->add_setting( 'prime-business-team-columns-setting', array(
      'capability'        => 'edit_theme_options',
      'default'           =>  'four',
      'sanitize_callback' => 'prime_business_sanitize_select',
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-team-columns-control', array(
      'label'       => __( 'Number of Columns', 'prime-business' ),
      'section'     => 'prime-business-team-section',
      'settings'    => 'prime-business-team-columns-setting',
      'type'    =>  'select',
      'choices' =>  array(
                'six'   =>  __( 'Two', 'prime-business' ),
                'three' =>  __( 'Four', 'prime-business' ),
                'four'  =>  __( 'Three', 'prime-business' ),
              ),
      'active_callback' => 'prime_business_flag_is_team_members_diabled',
    ) ) );

    for ( $prime_business_count = 1; $prime_business_count < 9; $prime_business_count++ ) {

        // Call Team Member pages
        $wp_customize->add_setting( "prime-business-member-content-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'absint'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-member-content-control-$prime_business_count", array(
          /* Translators: %s: FMember number */
          'label'           => sprintf( __( 'Select Member %s', 'prime-business' ), $prime_business_count ),
          'description'     => __( 'Select from your existing pages for member content.', 'prime-business' ),
          'section'         => 'prime-business-team-section',
          'settings'        => "prime-business-member-content-setting-$prime_business_count",
          'type'            => 'dropdown-pages',
          'active_callback' => 'prime_business_flag_is_team_members_diabled',
        ) ) );

        $wp_customize->selective_refresh->add_partial( "prime-business-member-content-partial-$prime_business_count", array(
            'selector'            => ".member-content-$prime_business_count",
            'container_inclusive' => true,
            'settings'            => "prime-business-member-content-setting-$prime_business_count",
        ) );
    }

    /******************************** Team Member Background Color *****************************/
    $wp_customize->add_setting( 'prime_business_team_member_background_color_setting', array(
      'default'   => '#fff',
      'sanitize_callback' => 'sanitize_hex_color',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'prime_business_team_member_background_color_control', array(
      'section'  => 'prime-business-team-section',
      'label'    => esc_html__( 'Background Color', 'prime-business' ),
      'settings' => 'prime_business_team_member_background_color_setting',
      'active_callback' => 'prime_business_flag_is_team_members_diabled',
    ) ) );

/*******************************************************************************
 * Homepage Features Section
 ******************************************************************************/
    $wp_customize->add_section( 'prime-business-features-section', array(
      'title'       =>  __( 'Features Section', 'prime-business' ),
      'priority'    =>  10,
      'panel'       =>  'prime-business-frontpage'
    ) );

    // Features Switch
    $wp_customize->add_setting( 'prime-business-features-switch-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-features-switch-control', array(
      'label'       => __( 'Enable Features?', 'prime-business' ),
      'section'     => 'prime-business-features-section',
      'settings'    => 'prime-business-features-switch-setting',
      'type'        => 'ios',
    ) ) );

    // Features Subtitle - Text Field
    $wp_customize->add_setting( 'prime-business-features-subtitle-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'sanitize_text_field'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-features-subtitle-control', array(
      'label'           => __( 'Features Subtitle', 'prime-business' ),
      'section'         => 'prime-business-features-section',
      'settings'        => 'prime-business-features-subtitle-setting',
      'type'            => 'text',
      'active_callback' => 'prime_business_flag_is_features_diabled',
    ) ) );

    $wp_customize->selective_refresh->add_partial( "prime-business-features-subtitle-partial", array(
        'selector'            => ".features-subtitle",
        'container_inclusive' => true,
        'settings'            => "prime-business-features-subtitle-setting",
    ) );

    // Features Title - Text Field
    $wp_customize->add_setting( 'prime-business-features-title-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'sanitize_text_field'
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'prime-business-features-title-control', array(
      'label'           => __( 'Features Title', 'prime-business' ),
      'section'         => 'prime-business-features-section',
      'settings'        => 'prime-business-features-title-setting',
      'type'            => 'text',
      'active_callback' => 'prime_business_flag_is_features_diabled',
    ) ) );

    $wp_customize->selective_refresh->add_partial( "prime-business-features-title-partial", array(
        'selector'            => ".features-title",
        'container_inclusive' => true,
        'settings'            => "prime-business-features-title-setting",
    ) );

    for ( $prime_business_count = 1; $prime_business_count < 5; $prime_business_count++ ) {
        // Call Feature pages
        $wp_customize->add_setting( "prime-business-feature-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'absint'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-feature-control-$prime_business_count", array(
          /* Translators: %s: Feature number */
          'label'           => sprintf( __( 'Select Feature %s', 'prime-business' ), $prime_business_count ),
          'description'     =>  __( 'Select from your existing pages for feature content', 'prime-business' ),
          'section'         => 'prime-business-features-section',
          'settings'        => "prime-business-feature-setting-$prime_business_count",
          'type'            => 'dropdown-pages',
          'active_callback' => 'prime_business_flag_is_features_diabled',
        ) ) );

        $wp_customize->selective_refresh->add_partial( "prime-business-feature-partial-$prime_business_count", array(
            'selector'            => ".feature-content-$prime_business_count",
            'container_inclusive' => true,
            'settings'            => "prime-business-feature-setting-$prime_business_count",
        ) );

        // Features Icon - Text Field
        $wp_customize->add_setting( "prime-business-feature-icon-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'sanitize_text_field',
          'default'           =>  'fa-star'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-feature-icon-control-$prime_business_count", array(
          /* Translators: %s: Icon number */
          'label'           => sprintf( __( 'Feature Icon %s', 'prime-business' ), $prime_business_count ),
          /* Translators: %s: Fontawesome url */
          'description'     => sprintf( __( 'Please input icon as eg: fa-star. Find Font-awesome icons %1$shere%2$s', 'prime-business' ), '<a href="' . esc_url( 'https://fontawesome.com/v4.7.0/cheatsheet/' ) . '" target="_blank">', '</a>' ),
          'section'         => 'prime-business-features-section',
          'settings'        => "prime-business-feature-icon-setting-$prime_business_count",
          'type'            => 'text',
          'active_callback' => 'prime_business_flag_is_features_diabled',
        ) ) );
    }

    /******************************** Feature Background Color *****************************/
    $wp_customize->add_setting( 'prime_business_feature_background_color_setting', array(
      'default'   => '#fff',
      'sanitize_callback' => 'sanitize_hex_color',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'prime_business_feature_background_color_control', array(
      'section'  => 'prime-business-features-section',
      'label'    => esc_html__( 'Background Color', 'prime-business' ),
      'settings' => 'prime_business_feature_background_color_setting',
      'active_callback' => 'prime_business_flag_is_features_diabled',
    ) ) );

  /*******************************************************************************
 * Homepage Testimonials Section
 ******************************************************************************/
   $wp_customize->add_section( 'prime-business-testimonials-section', array(
      'title'       =>  __( 'Testimonials Section', 'prime-business' ),
      'priority'    =>  10,
      'panel'       =>  'prime-business-frontpage'
    ) );

    // Testimonials Switch
    $wp_customize->add_setting( 'prime-business-testimonials-switch-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-testimonials-switch-control', array(
      'label'       => __( 'Enable Testimonials?', 'prime-business' ),
      'section'     => 'prime-business-testimonials-section',
      'settings'    => 'prime-business-testimonials-switch-setting',
      'type'        => 'ios',
    ) ) );

    for ( $prime_business_count = 1; $prime_business_count < 7; $prime_business_count++ ) {
        // Call Testimonial pages
        $wp_customize->add_setting( "prime-business-testimonial-setting-$prime_business_count", array(
          'capability'        => 'edit_theme_options',
          'sanitize_callback' => 'absint'
        ) );

        $wp_customize->add_control( new WP_Customize_Control( $wp_customize, "prime-business-testimonial-control-$prime_business_count", array(
          /* Translators: %s: Testimonial Number */
          'label'           => sprintf( __( 'Select Testimonial %s', 'prime-business' ), $prime_business_count ),
          'description'     => __( 'Select from your existing pages for testimonial content. Add Featured Image as testimonial author.', 'prime-business' ),
          'section'         => 'prime-business-testimonials-section',
          'settings'        => "prime-business-testimonial-setting-$prime_business_count",
          'type'            => 'dropdown-pages',
          'active_callback' => 'prime_business_flag_is_testimonials_diabled',
        ) ) );

        $wp_customize->selective_refresh->add_partial( "prime-business-testimonial-partial-$prime_business_count", array(
            'selector'            => ".testimonial-content-$prime_business_count",
            'container_inclusive' => true,
            'settings'            => "prime-business-testimonial-setting-$prime_business_count",
        ) );
    }

   // Upload Testimonial BG - Image
    $wp_customize->add_setting( 'prime-business-testimonial-bg-setting', array(
      'sanitize_callback' => 'prime_business_sanitize_image',
    ) );

    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'ct-default-featured-control', array(
      'label'           =>  __( 'Upload Testimonial Background Image', 'prime-business' ),
      'section'         =>  'prime-business-testimonials-section',
      'settings'        =>  'prime-business-testimonial-bg-setting',
      'active_callback' =>  'prime_business_flag_is_testimonials_diabled',
    ) ) );

    for ( $prime_business_count = 0; $prime_business_count < 4; $prime_business_count++ ) {

      $prime_business_individual_option = array(
        __( 'Enable Carousel Dots?', 'prime-business' ),
        __( 'Enable Arrows?', 'prime-business' ),
        __( 'Enable Fade Effect?', 'prime-business' ),
        __( 'Enable Autoplay?', 'prime-business' ),
      );

      // Slider Settings
      $wp_customize->add_setting( "prime-business-testimonial-options-setting-$prime_business_count", array(
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'absint',
        'default'           => true
      ) );

      $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, "prime-business-testimonial-options-control-$prime_business_count", array(
        'label'           => sprintf( '%s', $prime_business_individual_option[ $prime_business_count ] ),
        'section'         => 'prime-business-testimonials-section',
        'settings'        => "prime-business-testimonial-options-setting-$prime_business_count",
        'type'            => 'ios',
        'active_callback' => 'prime_business_flag_is_testimonials_diabled',
      ) ) );
    }

 /*******************************************************************************
 * Homepage Editor Section
 ******************************************************************************/

    $wp_customize->add_section( 'prime-business-editor-section', array(
      'title'       =>  __( 'Editor', 'prime-business' ),
      'priority'    =>  10,
      'panel'       =>  'prime-business-frontpage'
    ) );

    // Editor Switch
    $wp_customize->add_setting( 'prime-business-editor-switch-setting', array(
      'capability'        => 'edit_theme_options',
      'sanitize_callback' => 'absint',
      'default'           => false
    ) );

    $wp_customize->add_control( new Prime_Business_Customizer_Toggle_Control( $wp_customize, 'prime-business-editor-switch-control', array(
      'label'       => __( 'Enable Editor?', 'prime-business' ),
      'section'     => 'prime-business-editor-section',
      'settings'    => 'prime-business-editor-switch-setting',
      'type'        => 'ios',
    ) ) );

}

add_action( 'customize_register', 'prime_business_homepage_setup');

/**
 * Sanitization: image
 */
function prime_business_sanitize_select( $input ) {
  $valid = array(
    'six'   => 'Two',
    'four'  => 'Three',
    'three' =>  'Four',
  );

  if ( array_key_exists( $input, $valid ) ) {
    return $input;
  } else {
    return '';
  }
}

/**
 * Sanitization: image
 * Control: text, WP_Customize_Image_Control
 *
 * Sanitization callback for images.
 *
 * @uses  esc_url_raw()       http://codex.wordpress.org/Function_Reference/esc_url_raw
 */
function prime_business_sanitize_image( $input, $setting ) {
  return esc_url_raw( prime_business_validate_image( $input, $setting->default ) );
}

/**
 * Validation: image
 * Control: text, WP_Customize_Image_Control
 *
 * @uses  wp_check_filetype()   https://developer.wordpress.org/reference/functions/wp_check_filetype/
 * @uses  in_array()        http://php.net/manual/en/function.in-array.php
 */

function prime_business_validate_image( $input, $default = '' ) {
  // Array of valid image file types
  // The array includes image mime types
  // that are included in wp_get_mime_types()
  $mimes = array(
    'jpg|jpeg|jpe' => 'image/jpeg',
    'gif'          => 'image/gif',
    'png'          => 'image/png',
    'bmp'          => 'image/bmp',
    'tif|tiff'     => 'image/tiff',
    'ico'          => 'image/x-icon'
  );
  // Return an array with file extension
  // and mime_type
  $file = wp_check_filetype( $input, $mimes );
  // If $input has a valid mime_type,
  // return it; otherwise, return
  // the default.
  return ( $file['ext'] ? $input : $default );
}

get_template_part( '/inc/customizer/active-callbacks' );
