<?php
/**
 * Aamira functions and definitions.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package WordPress
 * @subpackage Necessary_Blocks
 * @since Aamira 1.0
 */

// Adds theme support for post formats.
if ( ! function_exists( 'aamira_post_format_setup' ) ) :
	/**
	 * Adds theme support for post formats.
	 *
	 * @since Aamira 1.0
	 *
	 * @return void
	 */
	function aamira_post_format_setup() {
		add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) );
		add_theme_support( 'title-tag' );
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'editor-styles' );
		add_theme_support( 'responsive-embeds' );
		add_theme_support( 'align-wide' );
		add_theme_support( 'post-thumbnails' );

		if(file_exists( get_parent_theme_file_path( 'assets/css/editor-style.css' ) )) {
			add_editor_style( 'assets/css/editor-style.css' );
		}

	// Add support for Block Styles.
	add_theme_support( 'wp-block-styles' );
    add_theme_support('woocommerce');

	// Enqueue editor styles.
	add_editor_style( array( 'assets/css/editor-style.css' ) );
	require get_parent_theme_file_path( '/inc/dashboard/dashboard.php' );
    // require get_parent_theme_file_path( '/inc/customizer/customizer.php' );

	}
endif;
add_action( 'after_setup_theme', 'aamira_post_format_setup' );


// Enqueues style.css on the front.
if ( ! function_exists( 'aamira_enqueue_styles' ) ) :
	/**
	 * Enqueues style.css on the front.
	 *
	 * @since Aamira 1.0
	 *
	 * @return void
	 */
	function aamira_enqueue_styles() {
		wp_enqueue_style(
			'aamira-style',
			get_parent_theme_file_uri( 'style.css' ),
			array(),
			wp_get_theme()->get( 'Version' )
		);
	}
endif;
add_action( 'wp_enqueue_scripts', 'aamira_enqueue_styles' );

// Registers custom block styles.
if ( ! function_exists( 'aamira_block_styles' ) ) :
	/**
	 * Registers custom block styles.
	 *
	 * @since Aamira 1.0
	 *
	 * @return void
	 */
	function aamira_block_styles() {
		register_block_style(
			'core/list',
			array(
				'name'         => 'checkmark-list',
				'label'        => __( 'Checkmark', 'aamira' ),
				'inline_style' => '
				ul.is-style-checkmark-list {
					list-style-type: "\2713";
				}

				ul.is-style-checkmark-list li {
					padding-inline-start: 1ch;
				}',
			)
		);
	}
endif;
add_action( 'init', 'aamira_block_styles' );

// Registers pattern categories.
if ( ! function_exists( 'aamira_pattern_categories' ) ) :
	/**
	 * Registers pattern categories.
	 *
	 * @since Aamira 1.0
	 *
	 * @return void
	 */
	function aamira_pattern_categories() {

		register_block_pattern_category(
			'aamira_page',
			array(
				'label'       => __( 'Pages', 'aamira' ),
				'description' => __( 'A collection of full page layouts.', 'aamira' ),
			)
		);

		register_block_pattern_category(
			'aamira_post-format',
			array(
				'label'       => __( 'Post formats', 'aamira' ),
				'description' => __( 'A collection of post format patterns.', 'aamira' ),
			)
		);
	}
endif;
add_action( 'init', 'aamira_pattern_categories' );

function aamira_theme_enqueue_admin_script($hook) {
    // Enqueue admin JS for notices
    wp_enqueue_script('theme-welcome-notice', get_template_directory_uri() . '/inc/dashboard/theme-welcome-notice.js', array('jquery'), '', true);
    
    // Localize script to pass data to JavaScript
    wp_localize_script('theme-welcome-notice', 'aamira_theme_localize', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce' => wp_create_nonce('aamira_theme_welcome_nonce'),
        'dismiss_nonce' => wp_create_nonce('aamira_theme_welcome_nonce'), // Nonce for dismissal
        'redirect_url' => admin_url('themes.php?page=theme-guide-page')
    ));
}
add_action('admin_enqueue_scripts', 'aamira_theme_enqueue_admin_script');


function aamira_theme_admin_theme_style() {
   wp_enqueue_style('aamira-theme-custom-admin-style', esc_url(get_template_directory_uri()) . '/inc/dashboard/dashboard.css');
}
add_action('admin_enqueue_scripts', 'aamira_theme_admin_theme_style');

/* Required Plugin Activation Code */
include_once get_parent_theme_file_path( 'inc/plugin-activation.php' );
require_once get_parent_theme_file_path( '/inc/dashboard/welcome-notice.php' );

