<?php
/**
 * Professional Painting functions and definitions
 *
 * @package Professional Painting
 */

if ( ! function_exists( 'professional_painting_setup' ) ) :
function professional_painting_setup() {

	global $content_width;

	if ( ! isset( $content_width ) ) {
		$content_width = 640;
	}

	// Theme version
	if ( ! defined( 'PROFESSIONAL_PAINTING_VERSION' ) ) {
		define( 'PROFESSIONAL_PAINTING_VERSION', wp_get_theme()->get( 'Version' ) );
	}

	// Load text domain
	load_theme_textdomain( 'professional-painting', get_template_directory() . '/languages' );

	// Theme supports
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );

	add_theme_support( 'custom-logo', array(
		'height'      => 240,
		'width'       => 240,
		'flex-height' => true,
	) );

	add_theme_support( 'custom-background', array(
		'default-color' => 'ffffff',
	) );

	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'align-wide' );
	add_theme_support( 'responsive-embeds' );

	// WooCommerce
	add_theme_support( 'woocommerce' );

	// 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/admin/theme-upsell.php' );

    require get_parent_theme_file_path( '/inc/customizer/customizer.php' );


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

/**
 * Enqueue scripts and styles
 */
function professional_painting_scripts() {

	$professional_painting_version = PROFESSIONAL_PAINTING_VERSION;

	// Main stylesheet
	wp_enqueue_style(
		'professional-painting-basic-style',
		get_stylesheet_uri(),
		array(),
		$professional_painting_version
	);

	// Animate CSS
	wp_enqueue_style(
		'animate-css',
		get_template_directory_uri() . '/assets/css/animate.css',
		array(),
		$professional_painting_version
	);

	// Font Awesome
	wp_enqueue_style(
		'fontawesome',
		get_template_directory_uri() . '/assets/font-awesome/css/all.css',
		array(),
		'7.0.0'
	);

	// Owl Carousel CSS
	wp_enqueue_style(
		'owl-carousel-style',
		get_template_directory_uri() . '/assets/css/owl-carousel.css',
		array(),
		$professional_painting_version
	);

	// WOW JS
	wp_enqueue_script(
		'wow-js',
		get_template_directory_uri() . '/assets/js/wow.js',
		array( 'jquery' ),
		$professional_painting_version,
		true
	);

	// Owl Carousel JS
	wp_enqueue_script(
		'owl-carousel-js',
		get_template_directory_uri() . '/assets/js/owl-carousel.js',
		array( 'jquery' ),
		$professional_painting_version,
		true
	);

	// Main Script
	wp_enqueue_script(
		'professional-painting-main-script',
		get_template_directory_uri() . '/assets/js/script.js',
		array( 'jquery', 'wow-js' ),
		$professional_painting_version,
		true
	);

	// RTL support
	wp_style_add_data( 'professional-painting-basic-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'professional_painting_scripts' );

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

function professional_painting_admin_theme_style() {
   wp_enqueue_style('professional-painting-custom-admin-style', esc_url(get_template_directory_uri()) . '/inc/dashboard/dashboard.css');
   wp_enqueue_style('professional-painting-admin-upsell-style', esc_url(get_template_directory_uri()) . '/assets/css/admin-style.css');
}
add_action('admin_enqueue_scripts', 'professional_painting_admin_theme_style');

add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );

// add_action( 'admin_init', function() {
//     update_option( 'essential_blocks_quick_setup_shown', true );
//     update_option( 'essential_blocks_user_type', 'old' );
//     remove_submenu_page( 'admin.php', 'eb-quick-setup' );
// });

// Block Patterns.
require get_template_directory() . '/block-patterns.php';
require get_template_directory() . '/custom-setting.php';
require get_template_directory() .'/inc/TGM/tgm.php';
require_once get_template_directory() . '/inc/dashboard/welcome-notice.php';

/**
 * Redirect to Pro upsell page after theme activation
 */

add_action('after_switch_theme', 'professional_painting_redirect_after_activation');
function professional_painting_redirect_after_activation() {
    if ( ! get_option( 'professional_painting_activation_redirect', false ) ) {
        update_option( 'professional_painting_activation_redirect', true );
        wp_safe_redirect( admin_url( 'themes.php?page=professional-painting-pro' ) );
        exit;
    }
}

add_action( 'admin_bar_menu', 'professional_painting_add_upgrade_button', 100 );

function professional_painting_add_upgrade_button( $professional_painting_wp_admin_bar ) {

    $professional_painting_theme_name = wp_get_theme()->get( 'Name' );

    $professional_painting_args = array(
        'id'    => 'professional_painting_upgrade',
        'title' => '<span style="color:#fff;font-weight:600;">
            🚀 Upgrade to ' . esc_html( $professional_painting_theme_name ) . ' Pro - 20% OFF 
            <span style="background:#ff5722;color:#fff;padding:2px 8px;border-radius:3px;margin-left:6px;">
                Buy Now
            </span>
        </span>',
        'href'  => esc_url( PROFESSIONAL_PAINTING_BUY_PRO ),
        'meta'  => array(
            'class'  => 'professional-painting-upgrade-btn',
            'title'  => 'Upgrade to Pro',
            'target' => '_blank'
        )
    );

    $professional_painting_wp_admin_bar->add_node( $professional_painting_args );
}