<?php
/**
 * Plugin Name: MCP Server & AI Experiments – WooCommerce Compatible
 * Plugin URI:  https://atlasaidev.com/
 * Description: AI-powered WordPress hub with 80+ abilities, built-in MCP server, AI experiments in the block editor, role-based access control, JWT auth, workflow builder, and WooCommerce support.
 * Version:     1.5.4
 * Author:      Azizul Hasan
 * Author URI:  https://atlasaidev.com
 * Text Domain: ai-workflow-automation-ai-agent-hub
 * Domain Path: /languages
 * Requires PHP: 7.4
 * Requires at least: 6.8
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

//// Composer autoloader.
//$awfah_autoload = __DIR__ . '/vendor/autoload.php';

// Load the Jetpack autoloader instead of vendor/autoload.php
$awfah_autoload =  plugin_dir_path(__FILE__) . 'vendor/autoload_packages.php';

if ( file_exists( $awfah_autoload ) ) {
    require_once $awfah_autoload;
} else {
    // Optional: admin notice if vendor missing.
    add_action(
        'admin_notices',
        static function () {
            if ( current_user_can( 'manage_options' ) ) {
                echo '<div class="notice notice-error"><p>';
                echo esc_html__( 'AI Agent Hub: Composer dependencies are missing. Please run "composer install".', 'ai-workflow-automation-ai-agent-hub' );
                echo '</p></div>';
            }
        }
    );
    return;
}


// Ensure the Abilities API is loaded when installed as a Composer dependency.
$abilities_bootstrap = plugin_dir_path( __FILE__ ) . 'vendor/wordpress/abilities-api/abilities-api.php';
if ( ! function_exists( 'wp_register_ability' ) && file_exists( $abilities_bootstrap ) ) {
    require_once $abilities_bootstrap;
}

// Load pro-helpers before anything else.
require_once __DIR__ . '/src/Helpers/pro-helpers.php';

use AtlasAiDev\Awfah\Plugin;
use WordPress\AI_Client\AI_Client;

// Initialize WP AI Client.
add_action(
    'init',
    static function () {
        if ( class_exists( AI_Client::class ) ) {
            AI_Client::init();
        }
    }
);

// Bootstrap plugin.
add_action(
    'plugins_loaded',
    static function () {
        Plugin::instance();
    }
);