<?php
/**
 *
 * @link              https://ahsandev.com/
 * @since             1.0.0
 * @package           order_management_woo
 *
 * @wordpress-plugin
 * Plugin Name: Order Management for WooCommerce
 * Plugin URI: https://wordpress.org/plugins/order-management-woo/
 * Description: Powerful reporting and analytics tools for WooCommerce order management.
 * Version: 1.0.5
 * Author: Ahsan Khan
 * Author URI: https://ahsandev.com/
 * License: GPL-2.0+
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain: order-management-woo
 * Requires at least: 4.7
 * Tested up to: 6.9
 * Requires PHP: 7.1
 * Requires Plugins: woocommerce
 * WC requires at least: 6.9
 * WC tested up to: 10.3
 */
if ( ! defined( 'WPINC' ) ) {
	die;
}
define( 'order_management_woo_VERSION', '1.0.5' );

/**
 * Run on plugin activation
 */
function order_management_woo_activate() {

	// Check WooCommerce activation
	if ( ! class_exists( 'WooCommerce' ) ) {
		deactivate_plugins( plugin_basename( __FILE__ ) );

		wp_die(
			__( 'WooCommerce is not active. Please install and activate WooCommerce before using this plugin.', 'order-management-woo' ),
			__( 'Plugin Activation Error', 'order-management-woo' ),
			array( 'back_link' => true )
		);
	}
}
register_activation_hook( __FILE__, 'order_management_woo_activate' );

/**
 * Prevent the plugin from running if WooCommerce is deactivated later
 */
function order_management_woo_check_dep() {
	if ( ! class_exists( 'WooCommerce' ) ) {

		// Show admin notice
		add_action( 'admin_notices', function() {
			echo '<div class="error"><p><strong>Order Management for WooCommerce</strong> requires WooCommerce. Please activate WooCommerce.</p></div>';
		});

		return;
	}

	// WooCommerce active → load plugin normally
	require plugin_dir_path( __FILE__ ) . 'includes/class-order_management_woo.php';

	$plugin = new order_management_woo();
	$plugin->run();
}
add_action( 'plugins_loaded', 'order_management_woo_check_dep' );