<?php

/**
 * Plugin Name:       Conflict Radar
 * Plugin URI:        https://wordpress.org/plugins/conflict-radar/
 * Description:       Monitor plugin updates, detect conflicts, and get alerted before your site breaks.
 * Version:           1.0.0
 * Requires at least: 6.0
 * Requires PHP:      8.0
 * Author:            mamunitiw
 * Author URI:        https://profiles.wordpress.org/mamunitiw/
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       conflict-radar
 *
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( function_exists( 'conflict_radar_fs' ) ) {
    conflict_radar_fs()->set_basename( false, __FILE__ );
} else {
    // DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE `function_exists` CALL ABOVE TO PROPERLY WORK.
    if ( !function_exists( 'conflict_radar_fs' ) ) {
        // Create a helper function for easy SDK access.
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Freemius SDK convention.
        function conflict_radar_fs() {
            // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Freemius SDK convention.
            global $conflict_radar_fs;
            if ( !isset( $conflict_radar_fs ) ) {
                // Include the Freemius SDK — manually vendored at vendor/freemius/ (per
                // Freemius/wp.org compliance). It is kept tracked despite /vendor/* being
                // ignored via the .gitignore exception !/vendor/freemius/.
                require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
                // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Freemius SDK convention.
                $conflict_radar_fs = fs_dynamic_init( array(
                    'id'               => '32476',
                    'slug'             => 'conflict-radar',
                    'type'             => 'plugin',
                    'public_key'       => 'pk_80afc560bdf85529493113acf8417',
                    'is_premium'       => false,
                    'has_addons'       => false,
                    'has_paid_plans'   => true,
                    'is_org_compliant' => true,
                    'menu'             => array(
                        'slug'    => 'conflict-radar',
                        'support' => false,
                    ),
                    'is_live'          => true,
                ) );
            }
            return $conflict_radar_fs;
        }

        // Init Freemius.
        conflict_radar_fs();
        // Signal that SDK was initiated.
        // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Freemius SDK convention.
        do_action( 'conflict_radar_fs_loaded' );
    }
    /*
     * ------------------------------------------------------------------
     * Conflict Radar bootstrap — runs once Freemius is initialised above.
     * ------------------------------------------------------------------
     */
    require_once __DIR__ . '/vendor/autoload.php';
    // Path/URL anchors used by admin templates and asset enqueues (Phase 4).
    define( 'CONFLICT_RADAR_FILE', __FILE__ );
    define( 'CONFLICT_RADAR_DIR', plugin_dir_path( __FILE__ ) );
    define( 'CONFLICT_RADAR_URL', plugin_dir_url( __FILE__ ) );
    define( 'CONFLICT_RADAR_VERSION', '1.0.0' );
    // Pro version constant. Defined on plugins_loaded priority 1 — BEFORE Plugin
    // boots at default 10 — and ONLY when Freemius reports the premium build.
    // Never define at file-load time: calling conflict_radar_fs() before Freemius initialises
    // would fatal. is__premium_only() is a real Freemius method (double underscore).
    add_action( 'plugins_loaded', function () {
        if ( function_exists( 'conflict_radar_fs' ) && conflict_radar_fs()->is__premium_only() ) {
            if ( !defined( 'CONFLICT_RADAR_PRO_VERSION' ) ) {
                define( 'CONFLICT_RADAR_PRO_VERSION', true );
            }
        }
    }, 1 );
    // Uninstall cleanup via the Freemius after_uninstall action (NOT uninstall.php,
    // which Freemius forbids). Uninstaller::cleanup() drops the tables + options.
    conflict_radar_fs()->add_action( 'after_uninstall', array('\\ConflictRadar\\Core\\Uninstaller', 'cleanup') );
    register_activation_hook( __FILE__, array('\\ConflictRadar\\Core\\Activator', 'activate') );
    register_deactivation_hook( __FILE__, array('\\ConflictRadar\\Core\\Deactivator', 'deactivate') );
    // Boot the orchestrator once on plugins_loaded. Default priority 10 — the Pro
    // constant above lands first at priority 1, so it exists before any class
    // checks defined( 'CONFLICT_RADAR_PRO_VERSION' ).
    add_action( 'plugins_loaded', static function () {
        ( new \ConflictRadar\Core\Plugin() )->run();
    } );
}