<?php
/**
 * Plugin Name: AISaleBot
 * Description: AI-powered sales chatbot integration for WordPress and WooCommerce.
 * Version:     1.0.0
 * Author:      AI Brain Solution
 * Author URI:  https://aisalebot.io/
 * License:     GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: aisalebot
 */

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

define( 'AICSAPP_PATH', plugin_dir_path( __FILE__ ) );
define( 'AICSAPP_URL', plugin_dir_url( __FILE__ ) );
define( 'AICSAPP_VER', '1.0.0' );

require_once AICSAPP_PATH . 'includes/Admin.php';
require_once AICSAPP_PATH . 'includes/Data.php';
require_once AICSAPP_PATH . 'includes/Helpers.php';

// Init admin
\AICSAPP\Admin::init();

/**
 * Frontend loader
 * - Fixed script source
 * - User provides Chatbot ID
 * - Loads only when enabled
 */
add_action( 'wp_footer', function () {

    $enabled    = (int) get_option( 'aicsapp_enabled', 0 );
    $chatbot_id = get_option( 'aicsapp_chatbot_id' );

    if ( ! $enabled || empty( $chatbot_id ) ) {
        return;
    }
    ?>
    <!-- AISaleBot -->
    <script
        src="https://aisalebot.io/chatbot_widget/chatbot-widget.js"
        data-id="<?php echo esc_attr( $chatbot_id ); ?>">
    </script>
    <!-- /AISaleBot -->
    <?php
}, 9999 );
