<?php

/**
 * The plugin bootstrap file
 *
 * @link              https://aiforwoo.com
 * @since             1.0.0
 * @package           Ai_Product_Tools
 *
 * @wordpress-plugin
 * Plugin Name:       AI Product Tools – Bulk Product Content Generator & AI Toolkit for WooCommerce
 * Plugin URI:        https://aiforwoo.com
 * Description:       All-in-One AI Suite for WooCommerce: Generate product descriptions, titles, tags, FAQs, alt text, SEO meta & chatbot via top AI models.
 * Version:           2.6.4
 * Requires at least: 6.8
 * Requires PHP:      7.4
 * Author:            Dogu Pekgoz
 * Author URI:        https://aiforwoo.com/
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       ai-product-tools
 * Domain Path:       /languages
 * 
 */
if ( !defined( 'WPINC' ) ) {
    die;
}
$_aipt_is_premium_dir = basename( dirname( __FILE__ ) ) === 'ai-product-tools-premium';
if ( function_exists( 'aipt_fs' ) ) {
    aipt_fs()->set_basename( $_aipt_is_premium_dir, __FILE__ );
    return;
}
$_aipt_active_plugins = (array) get_option( 'active_plugins', [] );
if ( is_multisite() ) {
    $_aipt_active_plugins = array_merge( $_aipt_active_plugins, array_keys( (array) get_site_option( 'active_sitewide_plugins', [] ) ) );
}
$_aipt_sibling_slug = ( $_aipt_is_premium_dir ? 'ai-product-tools/ai-product-tools.php' : 'ai-product-tools-premium/ai-product-tools.php' );
$_aipt_sibling_is_active = in_array( $_aipt_sibling_slug, $_aipt_active_plugins, true );
if ( $_aipt_sibling_is_active ) {
    if ( !$_aipt_is_premium_dir ) {
        return;
    }
    $_aipt_free_slug = 'ai-product-tools/ai-product-tools.php';
    $_aipt_updated = array_values( array_diff( (array) get_option( 'active_plugins', [] ), [$_aipt_free_slug] ) );
    update_option( 'active_plugins', $_aipt_updated );
    if ( is_multisite() ) {
        $_aipt_network = (array) get_site_option( 'active_sitewide_plugins', [] );
        if ( isset( $_aipt_network[$_aipt_free_slug] ) ) {
            unset($_aipt_network[$_aipt_free_slug]);
            update_site_option( 'active_sitewide_plugins', $_aipt_network );
        }
    }
}
unset(
    $_aipt_is_premium_dir,
    $_aipt_active_plugins,
    $_aipt_sibling_slug,
    $_aipt_sibling_is_active,
    $_aipt_updated,
    $_aipt_network,
    $_aipt_free_slug
);
if ( !defined( 'AIPT_VERSION' ) ) {
    define( 'AIPT_VERSION', '2.6.4' );
}
if ( !defined( 'AIPT_MIN_WP_VERSION' ) ) {
    define( 'AIPT_MIN_WP_VERSION', '6.8' );
}
if ( !defined( 'AIPT_PLUGIN_DIR' ) ) {
    define( 'AIPT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( !defined( 'AIPT_PLUGIN_FILE' ) ) {
    define( 'AIPT_PLUGIN_FILE', __FILE__ );
}
if ( !defined( 'AIPT_PLUGIN_URL' ) ) {
    define( 'AIPT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
    require_once dirname( __FILE__ ) . '/vendor/autoload.php';
}
if ( function_exists( 'aipt_fs' ) ) {
    aipt_fs()->set_basename( false, __FILE__ );
} else {
    if ( !function_exists( 'aipt_fs' ) ) {
        function aipt_fs() {
            global $aipt_fs;
            if ( !isset( $aipt_fs ) ) {
                require_once dirname( __FILE__ ) . '/vendor/freemius/wordpress-sdk/start.php';
                $aipt_fs = fs_dynamic_init( array(
                    'id'               => '15570',
                    'slug'             => 'ai-product-tools',
                    'type'             => 'plugin',
                    'public_key'       => 'pk_bebac4a4b8beed031101136867398',
                    'is_premium'       => false,
                    'has_addons'       => false,
                    'has_paid_plans'   => true,
                    'menu'             => array(
                        'slug'       => 'ai-product-tools',
                        'first-path' => 'admin.php?page=ai-product-tools',
                        'support'    => false,
                    ),
                    'is_live'          => true,
                    'is_org_compliant' => true,
                ) );
                if ( !class_exists( 'WooCommerce' ) ) {
                    $aipt_fs->add_filter( 'redirect_on_activation', '__return_false' );
                    $aipt_fs->add_filter( 'default_redirect_on_activation', '__return_false' );
                }
            }
            return $aipt_fs;
        }

        aipt_fs();
        do_action( 'aipt_fs_loaded' );
        aipt_fs()->add_action( 'after_uninstall', ['\\AIPT\\Core\\Uninstaller', 'cleanup'] );
    }
    register_activation_hook( __FILE__, function () {
        require_once AIPT_PLUGIN_DIR . 'src/Core/Activator.php';
        \AIPT\Core\Activator::activate();
        set_transient( 'aipt_activation_redirect', true, 30 );
    } );
    register_deactivation_hook( __FILE__, function () {
        require_once AIPT_PLUGIN_DIR . 'src/Core/Deactivator.php';
        \AIPT\Core\Deactivator::deactivate();
    } );
    add_action( 'plugins_loaded', function () {
        if ( !class_exists( 'WooCommerce' ) ) {
            new \AIPT\Admin\Notices();
            return;
        }
        $_aipt_stored_dir = get_option( 'aipt_active_plugin_dir', '' );
        $_aipt_current_dir = basename( AIPT_PLUGIN_DIR );
        if ( $_aipt_stored_dir !== $_aipt_current_dir ) {
            update_option( 'aipt_active_plugin_dir', $_aipt_current_dir, false );
            require_once AIPT_PLUGIN_DIR . 'src/Core/Activator.php';
            \AIPT\Core\Activator::activate();
        }
        require_once AIPT_PLUGIN_DIR . 'src/Core/Database/Migration.php';
        \AIPT\Core\Database\Migration::get_instance();
        require_once AIPT_PLUGIN_DIR . 'src/Core/Init.php';
        \AIPT\Core\Init::get_instance();
    } );
}