<?php
/*--------------------------------
Theme Setup
----------------------------------*/

if ( !function_exists( 'glamer_setup' ) ):

   /**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */

    function glamer_setup() {
        // Load text domain
        load_theme_textdomain( 'glamer', get_template_directory() . '/languages' );

        // Add default posts and comments RSS feed links to head.
        add_theme_support( 'automatic-feed-links' );

        // Title tag
        add_theme_support( 'title-tag' );

        // Post thumbnail
        add_theme_support( 'post-thumbnails' );

        //Custom image size
		add_image_size( 'glamer-large', 1320, 700, true );
        add_image_size( 'glamer-medium-grid', 380, 280, true );
        add_image_size( 'glamer-learg-grid', 380, 435, true );
        add_image_size( 'glamer-author-grid', 430, 490, true );
        //Post Formats
        add_theme_support( 'post-formats', array(
            'gallery',
            'quote',
            'video',
            'image',
            'link',
            'audio',
        ) );

        // Register navigation menus
        register_nav_menus(
            array(
                'mainmenu' => esc_html__( 'Main Menu', 'glamer' ),
            )
        );

        // HTML5 markup
        add_theme_support(
            'html5',
            array(
                'search-form',
                'comment-form',
                'comment-list',
                'gallery',
                'caption',
                'style',
                'script',
            )
        );
        
        // Set up the WordPress core custom background feature.
        add_theme_support( 'custom-background', apply_filters( 
            'glamer_custom_background_args', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        ) ) );

        // Add theme support for selective refresh for widgets.
        add_theme_support( 'customize-selective-refresh-widgets' );

        // Add support for core custom logo.
        add_theme_support( 'custom-logo', array(
            'height'      => 250,
            'width'       => 250,
            'flex-width'  => true,
            'flex-height' => true,
        ));

        // Gutenberg
        add_theme_support(
            'gutenberg',
            array( 'wide-images' => true )
        );

        // Align wide
        add_theme_support( 'align-wide' );

        // Block style
        add_theme_support( 'wp-block-styles' );
        // Default color palette
        add_theme_support( 'editor-color-palette', array(
            array(
                'name'  => esc_html__( 'Deep Black', 'glamer' ),
                'slug'  => 'black',
                'color' => '#000000',
            ),
            array(
                'name'  => esc_html__( 'Medium Black', 'glamer' ),
                'slug'  => 'medium-black',
                'color' => '#131923',
            ),
            array(
                'name'  => esc_html__( 'Light Green', 'glamer' ),
                'slug'  => 'light-green',
                'color' => '#00fcfa',
            ),

            array(
                'name'  => esc_html__( 'Deep Blue', 'glamer' ),
                'slug'  => 'Deep-blue',
                'color' => '#003796',
            ),

            array(
                'name'  => esc_html__( 'Light Yellow', 'glamer' ),
                'slug'  => 'light-yellow',
                'color' => '#ffe34c',
            ),
        ) );

        // Responsive Embeds
        add_theme_support( "responsive-embeds" );
        
        // Editor style
		add_theme_support( 'editor-styles' );

		// Editor style css
		add_editor_style( 'assets/css/editor-style.css' );

        // Removed Widget Blocks
        //remove_theme_support('widgets-block-editor');
    }
endif;

add_action( 'after_setup_theme', 'glamer_setup' );

//Set the content width in pixels, based on the theme's design and stylesheet.
function glamer_content_width() {
    $GLOBALS['content_width'] = apply_filters( 'glamer_content_width', 1140 );
}
add_action( 'after_setup_theme', 'glamer_content_width', 0 );

// Register a new style for the 'core/paragraph' block.
function glamer_register_block_styles() {
    register_block_style(
        'core/paragraph',
        array(
            'name'  => 'fancy-paragraph',
            'label' => __('Fancy Paragraph', 'glamer'),
            'inline_style' => '.wp-block-paragraph.is-style-fancy-paragraph { font-weight: bold; font-style: italic; color: #C57642; }',
        )
    );
}
add_action('init', 'glamer_register_block_styles');

function glamer_register_simple_block_pattern() {
    register_block_pattern(
        'glamer/tp-heading-paragraph', // Unique name for the block pattern
        array(
            'title'   => __('Simple Heading and Paragraph', 'glamer'), // Title of the pattern
            'content' => '<!-- wp:heading -->
                          <h2>' . __('Your Heading Here', 'glamer') . '</h2>
                          <!-- /wp:heading -->
                          <!-- wp:paragraph -->
                          <p>' . __('Your paragraph text goes here.', 'glamer') . '</p>
                          <!-- /wp:paragraph -->',
        )
    );
}
add_action('init', 'glamer_register_simple_block_pattern');