<?php
defined('ABSPATH') || exit;

use SmartPay\Activator;
use SmartPay\Deactivator;
use SmartPay\Updater;

require_once __DIR__ . '/vendor/autoload.php';

// Create The Application
$app = new SmartPay\Framework\Application(__DIR__);

// Register Service Providers
$app->register(SmartPay\Providers\AppServiceProvider::class);
$app->register(SmartPay\Providers\AdminServiceProvider::class);
$app->register(SmartPay\Providers\RouteServiceProvider::class);
$app->register(SmartPay\Providers\IntegrationServiceProvider::class);

register_activation_hook(SMARTPAY_PLUGIN_FILE, [Activator::class, 'boot']);

register_deactivation_hook(SMARTPAY_PLUGIN_FILE, [Deactivator::class, 'boot']);

Updater::boot();

add_action('plugins_loaded', function () {
    require_once(ABSPATH . '/wp-admin/includes/plugin.php');
    if (defined('SMARTPAY_PRO_VERSION')) {
        if (floatval(SMARTPAY_PRO_VERSION) < 2.6 && "##SMARTPAY_PRO_VERSION##" !== SMARTPAY_PRO_VERSION){
            add_action('admin_notices', 'smartpay_pro_deactivate_notice');
            deactivate_plugins(SMARTPAY_PRO_PLUGIN_FILE);
        }
    }
}, 20);

function smartpay_pro_deactivate_notice(){
	echo '<div class="error notice-warning"><p>'
	     . '<code>WP SmartPay Pro ' . esc_html( SMARTPAY_PRO_VERSION ) . '</code> '
	     . esc_html__( ' is not compatible with ', 'smartpay' ) . ' '
	     . '<code> WP SmartPay version 2.6.0 </code> '
	     . esc_html__( ' or higher. Please update ', 'smartpay' ) . ' '
	     . '<code> WP SmartPay Pro </code> '
	     . esc_html__( ' or downgrade ', 'smartpay' ) . ' '
	     . '<code> WP SmartPay </code>.'
	     . esc_html__( ' below ', 'smartpay' ) . ' '
	     . '<code> 2.6.0 </code>.'
	     . '</p></div>';
}

return $app;
