<?php
/**
 * Centu functions and definitions.
 *
 * @package Centu
 */
define( 'CENTU_THEME_DIR', get_template_directory() );
define( 'CENTU_THEME_URI', get_template_directory_uri() );

define( 'CENTU_THEME_NAME', 'centu' );
define( 'CENTU_THEME_VERSION', '1.0' );

if ( !function_exists( 'centu_setup' ) ) :

    function centu_setup() {

        load_theme_textdomain( 'centu', CENTU_THEME_DIR . '/languages' );

        add_theme_support( 'automatic-feed-links' );

        add_theme_support( 'title-tag' );

        add_theme_support( 'post-thumbnails' );
        /** Custom Image Sizes **/
        add_image_size( 'centu-1920x1080', 1920, 1080, true );
        add_image_size( 'centu-1200x500', 1200, 500, true );
        add_image_size( 'centu-740x400', 740, 400, true );
        add_image_size( 'centu-840x400', 840, 400, true );
        add_image_size( 'centu-550x550', 550, 550, true );
        add_image_size( 'centu-598x460', 598, 460, true );
        add_image_size( 'centu-589x228', 589, 228, true );
        add_image_size( 'centu-375x250', 375, 250, true );
        add_image_size( 'centu-279x228', 297, 228, true );
        add_image_size( 'centu-297x400', 297, 400, true );
        add_image_size( 'centu-100x70', 120, 100, true );
        add_image_size( 'centu-900x600', 900, 600, true );


        register_nav_menus( array(
            'primary' => esc_html__( 'Primary', 'centu' ),
        ) );

        add_theme_support( 'html5', array(
            'search-form',
            'comment-form',
            'comment-list',
            'gallery',
            'caption',
        ) );

        add_theme_support( 'post-formats', array(
            'aside',
            'image',
            'video',
            'quote',
            'link',
        ) );

        /**
        * Add support for core custom logo.
        *
        * @link https://codex.wordpress.org/Theme_Logo
        */
        add_theme_support(
            'custom-logo', array(
                'height'      => 1280,
                'width'       => 1920,
                'flex-width'  => false,
                'flex-height' => false,
            )
        );

        add_theme_support( 'woocommerce' );
        add_theme_support( 'wc-product-gallery-zoom' );
        add_theme_support( 'wc-product-gallery-lightbox' );
        add_theme_support( 'wc-product-gallery-slider' );
    }

endif;
add_action( 'after_setup_theme', 'centu_setup' );

function centu_content_width() {
    $GLOBALS[ 'content_width' ] = apply_filters( 'centu_content_width', 740 );
}

add_action( 'after_setup_theme', 'centu_content_width', 0 );


function centu_register_html5_support() {
    add_theme_support( 'html5', array( 'script', 'style' ) );
}
add_action( 'after_setup_theme', 'centu_register_html5_support' );


// Setup $content_width
if ( !isset( $content_width ) ) {
    $content_width = 800;
}

//Register widget area.
function centu_widgets_init() {
    register_sidebar( array(
        'name'          => esc_html__( 'Sidebar Right', 'centu' ),
        'id'            => 'centu-sidebar-right',
        'description'   => esc_html__( 'Add Widget to show in Right Sidebar', 'centu' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h4 class="widget-title"><span>',
        'after_title'   => '</span></h4>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Sidebar Left', 'centu' ),
        'id'            => 'centu-sidebar-left',
        'description'   => esc_html__( 'Add Widget to show in Left Sidebar', 'centu' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h4 class="widget-title"><span>',
        'after_title'   => '</span></h4>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Header Widget', 'centu' ),
        'id'            => 'centu-header-widget',
        'description'   => esc_html__( 'Add Widget to show in Header. Works with header Layout 3 and 6 only', 'centu' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h4 class="widget-title">',
        'after_title'   => '</h4>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer One', 'centu' ),
        'id'            => 'centu-footer-1',
        'description'   => esc_html__( 'Add Widget to show in Footer', 'centu' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h4 class="widget-title">',
        'after_title'   => '</h4>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer Two', 'centu' ),
        'id'            => 'centu-footer-2',
        'description'   => esc_html__( 'Add Widget to show in Footer', 'centu' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h4 class="widget-title">',
        'after_title'   => '</h4>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer Three', 'centu' ),
        'id'            => 'centu-footer-3',
        'description'   => esc_html__( 'Add Widget to show in Footer', 'centu' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h4 class="widget-title">',
        'after_title'   => '</h4>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer Four', 'centu' ),
        'id'            => 'centu-footer-4',
        'description'   => esc_html__( 'Add Widget to show in Footer', 'centu' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h4 class="widget-title">',
        'after_title'   => '</h4>',
    ) );
}

add_action( 'widgets_init', 'centu_widgets_init' );

//Enqueue scripts and styles.
function centu_scripts() {
    global $centu_options;
    $skin_color             = isset( $centu_options[ 'skin-color' ] ) ? $centu_options[ 'skin-color' ] : '#25bcea';
    $sticky_sidebar         = isset( $centu_options[ 'sticky-sidebar' ] ) ? $centu_options[ 'sticky-sidebar' ] : false;
    $enable_responsive      = isset( $centu_options[ 'enable-responsive' ] ) ? $centu_options[ 'enable-responsive' ] : true;
    $enable_custom_header   = isset( $centu_options[ 'enable-custom-header' ] ) ? $centu_options[ 'enable-custom-header' ] : true;
    $enable_plx_menu        = isset( $centu_options['enable-plx-menu'] ) ? $centu_options['enable-plx-menu'] : false;


    $centu_option_array = array(
        'skin_color'            => $skin_color,
        'sticky_sidebar'        => $sticky_sidebar,
        'enable_plx_menu'       => $enable_plx_menu
    );
    $font_families = array();

    $font_families[] = 'Roboto:400,400i,700,700i&display=swap';
    $font_families[] = 'Open+Sans:400,400i,700,700i&display=swap';

    $query_args = array(
        'family' => urlencode( implode( '|', $font_families ) ),
        'subset' => urlencode( 'latin,latin-ext' ),
    );
    $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );

    wp_enqueue_style( 'centu-fonts', $fonts_url, array(), CENTU_THEME_VERSION );

    
    wp_register_style( 'centu-comments', CENTU_THEME_URI . '/assets/css/comments.css', array(), CENTU_THEME_VERSION );
    wp_register_style( 'centu-sidebar', CENTU_THEME_URI . '/assets/css/sidebar.css', array(), CENTU_THEME_VERSION );
    
    if( false == $enable_custom_header || ! class_exists('ReduxFramework')){
        wp_enqueue_style( 'centu-headers', CENTU_THEME_URI . '/assets/css/headers.css', array(), CENTU_THEME_VERSION );
    }

    
    wp_enqueue_style( 'centu-footers', CENTU_THEME_URI . '/assets/css/footers.css', array(), CENTU_THEME_VERSION );
    

    if( is_singular() ){
        wp_enqueue_style( 'centu-blog', CENTU_THEME_URI . '/assets/css/blog.css', array(), CENTU_THEME_VERSION );   
    }

    wp_enqueue_style( 'centu-main', CENTU_THEME_URI . '/assets/css/main.css', array(), CENTU_THEME_VERSION );
    
    
    if( class_exists('woocommerce') ){
        wp_enqueue_style( 'centu-woocommerce', CENTU_THEME_URI . '/assets/css/woocommerce.css', array(), CENTU_THEME_VERSION );
    }

    
    
    wp_enqueue_style( 'centu-style', get_stylesheet_uri() );
    if ( $enable_responsive ) {
        wp_enqueue_style( 'centu-responsive', CENTU_THEME_URI . '/assets/css/responsive.css', array(), CENTU_THEME_VERSION );
    }

    wp_enqueue_script( 'jquery-stellar', CENTU_THEME_URI . '/assets/js/jquery.stellar.js', array( 'jquery' ), CENTU_THEME_VERSION, true );
    wp_enqueue_script( 'jquery-nav', CENTU_THEME_URI . '/assets/js/jquery.nav.js', array( 'jquery' ), CENTU_THEME_VERSION, true );
    
    
    
    
    wp_enqueue_script( 'theia-sticky-sidebar', CENTU_THEME_URI . '/assets/js/theia-sticky-sidebar.js', array( 'jquery' ), CENTU_THEME_VERSION, true );

    wp_enqueue_script( 'centu-main', CENTU_THEME_URI . '/assets/js/main.js', array( 'jquery' ), CENTU_THEME_VERSION, true );
    wp_localize_script( 'centu-main', 'centu_options', $centu_option_array );

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}

add_action( 'wp_enqueue_scripts', 'centu_scripts', 50 );

//Enqueue admin scripts and styles.
function centu_admin_scripts() {

    $currentScreen = get_current_screen();

    if( $currentScreen->id == 'toplevel_page_centu_options' ){
        wp_enqueue_style( 'centu-redux-style', CENTU_THEME_URI . '/inc/modified-redux/css/redux-style.css', array(), CENTU_THEME_VERSION );    
    }

    
}

add_action( 'admin_enqueue_scripts', 'centu_admin_scripts', 50 );


/**
 * Custom template tags for this theme.
 */
require CENTU_THEME_DIR . '/inc/template-tags.php';

/**
 * Customizer additions.
 */
require CENTU_THEME_DIR . '/inc/customizer.php';



/**
 * Custom functions that act independently of the theme templates.
 */
require CENTU_THEME_DIR . '/inc/icons/svg-icons.php';
require CENTU_THEME_DIR . '/inc/extras.php';
require CENTU_THEME_DIR . '/functions/header-functions.php';
require CENTU_THEME_DIR . '/functions/footer-functions.php';
require CENTU_THEME_DIR . '/functions/helper-functions.php';
require CENTU_THEME_DIR . '/functions/centu-functions.php';

/**
 * Custom Hooks and Filters
 */
require CENTU_THEME_DIR . '/inc/centu-woo.php';
require CENTU_THEME_DIR . '/inc/breadcrumbs.php';

/**
* Custom header
*/
require CENTU_THEME_DIR . '/inc/custom-header.php';

/**
* Welcome Page
*/
require CENTU_THEME_DIR . '/inc/welcome/welcome-config.php';

/**
* Starter content for theme
*/
require CENTU_THEME_DIR . '/inc/starter-contents.php';


if( ! class_exists('Centu_Companion')){
    require_once CENTU_THEME_DIR . '/inc/modified-redux/centu-config.php';    
    /** Dynamic Style * */
    require CENTU_THEME_DIR . '/inc/styles.php';
}





function centu_remove_redux_demo_link() {
    if ( class_exists( 'ReduxFrameworkPlugin' ) ) {
        remove_action( 'admin_notices', array( ReduxFrameworkPlugin::get_instance(), 'admin_notices' ) );
    }
}

add_action( 'init', 'centu_remove_redux_demo_link' );


/**
* Require files 
*/
$req_files = apply_filters('centu_require_files','__return_false');
         
if( $req_files != '__return_false' ){
  if( is_array($req_files) ){
      foreach ( $req_files as $files ){
        require $files;
      }
  }else{
    require $req_files;               
  }
}
