<?php
/**
 * Laundry Cleaning functions and definitions
 *
 * @package Laundry Cleaning
 */

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

	global $content_width;

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

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

	// Load text domain
	load_theme_textdomain( 'laundry-cleaning', 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' ) );

	if (! defined('LAUNDRY_CLEANING_VERSION')) {
		// Replace the version number of the theme on each release.
		define('LAUNDRY_CLEANING_VERSION', wp_get_theme()->get('Version'));
	}

	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', 'laundry_cleaning_setup' );

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

	$laundry_cleaning_version = LAUNDRY_CLEANING_VERSION;

	// Main stylesheet
	wp_enqueue_style(
		'laundry-cleaning-basic-style',
		get_stylesheet_uri(),
		array(),
		$laundry_cleaning_version
	);

	// Animate CSS
	wp_enqueue_style(
		'animate-css',
		get_template_directory_uri() . '/assets/css/animate.css',
		array(),
		$laundry_cleaning_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(),
		$laundry_cleaning_version
	);

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

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

	// Main Script
	wp_enqueue_script(
		'laundry-cleaning-main-script',
		get_template_directory_uri() . '/assets/js/script.js',
		array( 'jquery', 'wow-js' ),
		$laundry_cleaning_version,
		true
	);

	// RTL support
	wp_style_add_data( 'laundry-cleaning-basic-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'laundry_cleaning_scripts' );

function laundry_cleaning_enqueue_admin_script() {
	wp_enqueue_script(
		'laundry-cleaning-welcome-notice',
		get_template_directory_uri() . '/inc/dashboard/laundry-cleaning-welcome-notice.js',
		array( 'jquery' ),
		'',
		true
	);

	wp_localize_script(
		'laundry-cleaning-welcome-notice',
		'laundry_cleaning_localize',
		array(
			'ajax_url'      => admin_url( 'admin-ajax.php' ),
			'nonce'         => wp_create_nonce( 'laundry_cleaning_welcome_nonce' ),
			'dismiss_nonce' => wp_create_nonce( 'laundry_cleaning_welcome_nonce' ),
			'redirect_url'  => admin_url( 'themes.php?page=laundry-cleaning-guide-page' ),
		)
	);
}
add_action( 'admin_enqueue_scripts', 'laundry_cleaning_enqueue_admin_script' );

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

// Block Patterns.
require get_template_directory() . '/block-patterns.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', 'laundry_cleaning_redirect_after_activation');
function laundry_cleaning_redirect_after_activation() {
    if ( ! get_option( 'laundry_cleaning_activation_redirect', false ) ) {
        update_option( 'laundry_cleaning_activation_redirect', true );
        wp_safe_redirect( admin_url( 'themes.php?page=laundry-cleaning-pro' ) );
        exit;
    }
}

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

function laundry_cleaning_add_upgrade_button( $laundry_cleaning_wp_admin_bar ) {

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

    $laundry_cleaning_args = array(
        'id'    => 'laundry_cleaning_upgrade',
        'title' => '<span style="color:#fff;font-weight:600;">
            🚀 Upgrade to ' . esc_html( $laundry_cleaning_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( LAUNDRY_CLEANING_BUY_PRO ),
        'meta'  => array(
            'class'  => 'laundry-cleaning-upgrade-btn',
            'title'  => 'Upgrade to Pro',
            'target' => '_blank'
        )
    );

    $laundry_cleaning_wp_admin_bar->add_node( $laundry_cleaning_args );
}