<?php
	/**
	 *  We strongly recommend you do not edit this file or any other files
	 *  because at the next update you will lose all your customizations.
	 *
	 *  If you want to customize theme you can use a child theme or a plugin
	 *  extension.
	 *
	 *
	 *  @creaded    october 11, 2017
	 *  @updated    october 11, 2017
	 *
	 *  @package 	Gourmand
	 *  @since      Gourmand 0.0.2
	 *  @version    0.0.1
	 */

	// Just for my Presentation

	/*
		div.gourmand-site-identity div.custom-logo-wrapper{
			width: 80px;
		}
	*/

	include_once get_template_directory() . '/includes/main.php';
	include_once get_template_directory() . '/configs/main.php';
	include_once get_template_directory() . '/settings/main.php';

	/**
	 *	Setup Theme
	 */

	function gourmand_setup_theme()
	{
		global $content_width;

		$gourmand_content_width = apply_filters( 'gourmand_content_width', 1057 );

		if( empty( $content_width ) )
			$content_width = $gourmand_content_width;

		add_theme_support( 'content-width', absint( $content_width ) ) ;
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'post-thumbnails' );
		add_theme_support( 'title-tag' );


		/**
         *  Custom Background Image
         */

        $args = apply_filters( 'gourmand_custom_background', (array)gourmand_config::get( 'custom-background' ) );

		if( !empty( $args ) )
        	add_theme_support( 'custom-background', $args );


        /**
         *  Custom Header Image
         */

		$args = apply_filters( 'gourmand_custom_header', (array)gourmand_config::get( 'custom-header' ) );

		if( !empty( $args ) )
        	add_theme_support( 'custom-header', $args );


        /**
         *	Custom Logo
         */

		$args = apply_filters( 'gourmand_custom_logo', (array)gourmand_config::get( 'custom-logo' ) );

		if( !empty( $args ) )
        	add_theme_support( 'custom-logo', $args );


		/**
		 *	Additional Theme Support
		 */

		$cfgs = apply_filters( 'gourmand_additional_support', (array)gourmand_config::get( 'additional-support' ) );

		foreach( $cfgs as $key => $args ){
			if( !empty( $args ) ){
				add_theme_support( $key, $args );
			}

			else{
				add_theme_support( $key );
			}
		}


        /**
         *  Custom Images Sizes
         */

        $cfgs = apply_filters( 'gourmand_images_sizes', (array)gourmand_config::get( 'images-sizes' ) );

        foreach( $cfgs as $id => $size ){

            if( !(isset( $size[ 'width' ] ) && absint( $size[ 'width' ] ) > 0) )
                continue;

            if( !(isset( $size[ 'height' ] ) && absint( $size[ 'height' ] ) > 0) )
                continue;

            $width  = $size[ 'width' ];
            $height = $size[ 'height' ];
            $crop   = isset( $size[ 'crop' ] ) && (bool)$size[ 'crop' ];

            // add custom image size
            add_image_size( esc_attr( $id ), absint( $width ), absint( $height ), (bool)$crop );
        }

        set_post_thumbnail_size( 1057, 595 );


		/**
		 *  Internationalizations and Localization
		 */

		load_theme_textdomain( 'gourmand' , get_template_directory() . '/languages' );
	}

	add_action( 'after_setup_theme', 'gourmand_setup_theme' );


	/**
     *  Register Menus
     */

    function gourmand_register_menus()
    {
        $cfgs = apply_filters( 'gourmand_register_menus', (array)gourmand_config::get( 'menus' ) );

        if( !empty( $cfgs ) )
            register_nav_menus( $cfgs );
    }

    add_action( 'init', 'gourmand_register_menus' );


    /**
     *  Register Sidebars
     */

    function gourmand_register_sidebars()
    {
        $cfgs = apply_filters( 'gourmand_register_sidebars', (array)gourmand_config::get( 'sidebars' ) );

        if( !empty( $cfgs ) ){
            foreach( $cfgs as $sides => $sidebars ){
                foreach( $sidebars as $id => $sidebar ){
                    register_sidebar( $sidebar );
                }
            }
        }
    }

    add_action( 'widgets_init', 'gourmand_register_sidebars' );

	function gourmand_custom_styles()
	{
		gourmand_template::partial( 'templates/head/ie' );
		gourmand_template::partial( 'templates/head/style' );
		gourmand_template::partial( 'templates/head/hyphens' );
	}

	add_action( 'wp_head', 'gourmand_custom_styles' );

	/**
	 *	Enqueue Scripts and Styles
	 */

	add_action( 'admin_enqueue_scripts', array( 'gourmand_scripts', 'backend' ) );
	add_action( 'wp_enqueue_scripts', array( 'gourmand_scripts', 'frontend' ), 0 );
	add_action( 'in_admin_footer', array( 'gourmand_scripts', 'admin_footer' ) );
	add_action( 'wp_footer', array( 'gourmand_scripts', 'footer' ), 0 );
?>
