<?php
if ( ! function_exists( 'deltapress_setup' ) ) :
function deltapress_setup() {
	
	/*
	 * Define Theme Version
	 */
	define( 'DELTAPRESS_THEME_VERSION', '1.6' );
	

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

	/*
	 * Let WordPress manage the document title.
	 */
	add_theme_support( 'title-tag' );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 */
	add_theme_support( 'post-thumbnails' );

	/*
	 * Switch default core markup for search form, comment form, and comments
	 * to output valid HTML5.
	 */
	add_theme_support( 'html5', array(
		'search-form',
		'comment-form',
		'comment-list',
		'gallery',
		'caption',
	) );
	
	//Add selective refresh for sidebar widget
	add_theme_support( 'customize-selective-refresh-widgets' );
	
	//Add custom logo support
	add_theme_support('custom-logo');
	
	remove_theme_support( 'widgets-block-editor' );
	
}
endif;
add_action( 'after_setup_theme', 'deltapress_setup' );


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


add_filter( 'wp_get_attachment_image_attributes', function( $attr )
{
    if( isset( $attr['class'] )  && 'custom-logo' === $attr['class'] )
        $attr['class'] = 'custom-logo navbar-brand';

    return $attr;
} );


if ( ! function_exists( 'deltapress_setup_style' ) ) {
	function deltapress_setup_style() {
            add_theme_support( 'wp-block-styles' );
			add_editor_style('/assets/css/bootstrap.min.css');
			add_editor_style('/assets/css/all.min.css');
			add_editor_style('/assets/css/woo.css');
			add_editor_style( '/assets/css/block-widgets.css' );
			add_editor_style('style.css' );
        }
}
add_action( 'admin_init', 'deltapress_setup_style' );

 /**
 * Enqueue scripts and styles.
 */
function deltapress_scripts() {
	wp_enqueue_style( 'bootstrap-min-css', get_template_directory_uri() . '/assets/css/bootstrap.min.css' );	
	wp_enqueue_style( 'owl-carousel-min-css', get_template_directory_uri() . '/assets/css/owl.carousel.min.css' );
	wp_enqueue_style( 'woo-css', get_template_directory_uri() . '/assets/css/woo.css' );
	wp_enqueue_style( 'block-style-css', get_template_directory_uri() . '/assets/css/block-widgets.css' );
	wp_enqueue_style( 'lagecy-style-css', get_template_directory_uri() . '/assets/css/lagecy-widgets.css' );
	wp_enqueue_style( 'animate-min-css', get_template_directory_uri() . '/assets/css/animate.min.css' );
	wp_enqueue_style('font-awesome', get_template_directory_uri() . '/assets/css/all.min.css');
	
	wp_enqueue_style( 'deltapress-style', get_stylesheet_uri() );
	wp_enqueue_style( 'mediaquery-css', get_template_directory_uri() . '/assets/css/mediaquery.css' );
	
	// Scripts
	
	wp_enqueue_script( 'jquery' );
	wp_enqueue_script('bootstrap-bundle', get_template_directory_uri() . '/assets/js/bootstrap.bundle.js');
	wp_enqueue_script('owl-carousel-min-js', get_template_directory_uri() . '/assets/js/owl.carousel.min.js');
	wp_enqueue_script('owl-carousel2-thumbs-js', get_template_directory_uri() . '/assets/js/owl.carousel2.thumbs.js');
	wp_enqueue_script('imagesloaded-js', get_template_directory_uri() . '/assets/js/imagesloaded.pkgd.min.js');
	wp_enqueue_script('isotope-js', get_template_directory_uri() . '/assets/js/isotope.pkgd.min.js');
	wp_enqueue_script('masonry-js',get_template_directory_uri() . '/assets/js/masonry.pkgd.min.js',array('jquery'),'1.0.0',true);
	wp_enqueue_script('script-js',get_template_directory_uri() . '/assets/js/script.js',array('jquery'),'1.0.0',true);
	
	

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'deltapress_scripts' );


function deltapress_register_patterns() {
    $pattern_files = glob( get_template_directory_uri() . '/patterns/*.php' );

    foreach ( $pattern_files as $file ) {
        $pattern = include $file; // Include pattern array
        register_block_pattern( 'deltapress/' . basename( $file, '.php' ), $pattern );
    }
}
add_action( 'init', 'deltapress_register_patterns' );

function deltapress_register_block_styles() {
    if ( function_exists( 'register_block_style' ) ) {
        register_block_style(
            'core/button', // Button block
            array(
                'name'  => 'rounded-button',
                'label' => __( 'Rounded Button', 'deltapress' ),
                'inline_style' => '.wp-block-button.is-style-rounded-button a { border-radius: 50px; padding: 10px 20px; }',
            )
        );
    }
}
add_action( 'init', 'deltapress_register_block_styles' );