<?php
/**
 * The main plugin file for AI Try n Buy.
 *
 * This file is read by WordPress to generate the plugin information in the plugin
 * admin area. This file also includes all of the dependencies used by the plugin,
 * registers the activation and deactivation functions, and defines a function
 * that starts the plugin.
 *
 * @since             1.0.0
 * @package           Ai_Try_N_Buy
 *
 * @wordpress-plugin
 * Plugin Name:       Virtual Fit & Style Assistant for WooCommerce
 * Plugin URI:        https://trynbuy.edubrazeal.com/
 * Description:       A WooCommerce extension that allows customers to virtually try on products with Augmented Reality, get ai complete the look without manually selecting product to complete the look, get ai size suggestions to your customers.
 * Version:           1.0.3
 * Author:            Edu Brazeal
 * Author URI:        https://edubrazeal.com/
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       virtual-ai-fit-and-style-assistant
 * Domain Path:       /languages
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

/**
 * Current plugin version.
 */
define( 'AITNB_VERSION', '1.0.3' );

/**
 * Checks if WooCommerce is active. If not, deactivates the plugin.
 */
function aitnb_check_dependencies() {
    if ( ! function_exists( 'is_plugin_active' ) ) {
        include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    }

    if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
        deactivate_plugins( plugin_basename( __FILE__ ) );
        add_action( 'admin_notices', 'aitnb_display_wc_dependency_notice' );
        return;
    }
}
add_action( 'admin_init', 'aitnb_check_dependencies' );

/**
 * Displays an admin notice if WooCommerce is not active.
 */
function aitnb_display_wc_dependency_notice() {
    $message = sprintf(
        /* translators: %s: Plugin name */
        esc_html__( '%s requires WooCommerce to be installed and active. The plugin has been automatically deactivated.', 'virtual-ai-fit-and-style-assistant' ),
        '<strong>' . esc_html__( 'AI Try n Buy', 'virtual-ai-fit-and-style-assistant' ) . '</strong>'
    );
    echo '<div class="notice notice-error is-dismissible"><p>' . wp_kses_post( $message ) . '</p></div>';

	// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is checking WordPress core's activate parameter
    if ( isset( $_GET['activate'] ) ) {
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
        unset( $_GET['activate'] );
    }
}

/**
 * The code that runs during plugin activation.
 * This action is documented in includes/class-activator.php
 */
function aitnb_activate_plugin() {
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-activator.php';
	Aitnb_Activator::activate();
}

/**
 * The code that runs during plugin deactivation.
 * This action is documented in includes/class-deactivator.php
 */
function aitnb_deactivate_plugin() {
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-deactivator.php';
	Aitnb_Deactivator::deactivate();
}

register_activation_hook( __FILE__, 'aitnb_activate_plugin' );
register_deactivation_hook( __FILE__, 'aitnb_deactivate_plugin' );

/**
 * The core plugin class that is used to define internationalization,
 * admin-specific hooks, and public-facing site hooks.
 */
require plugin_dir_path( __FILE__ ) . 'includes/class-loader.php';

/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 *
 * @since    1.0.0
 */
function aitnb_run_plugin() {
	$plugin = new Aitnb_Loader();
	$plugin->run();
}

aitnb_run_plugin();