<?php
/**
 * chic-lifestyle Theme Customizer
 *
 * @package Chic Lifestyle
 */

$panels = array(
    'general-panel',
    'homepage-panel',
    'colors-fonts-panel',
    'header-options'
);

$general_sections = array(
    'colors',
    'typography',
    'sidebar',
    'blog-options',
    'post-options',
    'background',
    'pagination',
    'footer',
    'scroll-to-top',
);

$header_sections = array(
    'header-image',
    'site-identity',
    'header-search',
    'social-media',
    'header-layout',
);

require get_template_directory() . '/inc/google-fonts.php';

require get_template_directory() . '/inc/customizer/custom-controls.php';

add_action( 'customize_register', 'chic_lifestyle_change_homepage_settings_options' );
function chic_lifestyle_change_homepage_settings_options( $wp_customize ) {
    // Adjust priorities for built-in sections.
    $wp_customize->get_section('title_tagline')->priority = 12;
    $wp_customize->get_section('static_front_page')->priority = 13;

    // Remove the header text color control.
    $wp_customize->remove_control('header_textcolor');
}

$homepage_sections = array(
    'slider-section',
    'card-section',
    'blog-section',
    'featured-posts-section',
    'instagram-section',
);

if ( ! empty( $panels ) ) :
    foreach ( $panels as $panel ) {
        require get_template_directory() . '/inc/customizer/panels/' . $panel . '.php';
    }
endif;

if( ! empty( $general_sections ) ) {
    foreach( $general_sections as $section ) {
        require get_template_directory() . '/inc/customizer/sections/general-panel/' . $section . '.php';
    }
}

if( ! empty( $header_sections ) ) {
    foreach( $header_sections as $section ) {
        require get_template_directory() . '/inc/customizer/sections/header-options/' . $section . '.php';
    }
}

if ( ! empty( $homepage_sections ) ) :
    foreach ( $homepage_sections as $section ) {
        require get_template_directory() . '/inc/customizer/sections/homepage-sections/' . $section . '.php';
    }
endif;

require get_template_directory() . '/inc/customizer/sections/sort-homepage-section.php';

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function chic_lifestyle_customize_preview_js() {
    wp_enqueue_script( 'chic-lifestyle-customizer-preview', get_template_directory_uri() . '/inc/js/customizer.js', array( 'jquery' ), CHIC_LIFESTYLE_VERSION, true );
}
add_action( 'customize_preview_init', 'chic_lifestyle_customize_preview_js' );

/**
 * Binds Customizer CSS directives for free theme version.
 */
function chic_lifestyle_customizer_css() {
    wp_enqueue_style(
      'chic_lifestyle_customizer_css',
      get_template_directory_uri() . '/inc/css/customizer.css',
      array(),
      CHIC_LIFESTYLE_VERSION
    );
}
if ( fs_chic_lifestyle()->is_free_plan() ) {
    add_action( 'customize_controls_enqueue_scripts', 'chic_lifestyle_customizer_css' );
}


/**
 * Sanitization Functions
 */
require get_template_directory() . '/inc/customizer/sanitization-functions.php';

/**
 * Render Callback Functions
 */
require get_template_directory() . '/inc/customizer/render-functions.php';
