<?php
/**
 * Plugin Name:       STRYKE WP
 * Plugin URI:        https://www.strykemarketing.de
 * Description:       Modulares WordPress-Management: Remote-API, White-Label Branding, Google Drive Backup & Wartungsmodus — alles in einem Dashboard.
 * Version:           1.1.1
 * Requires at least: 6.0
 * Requires PHP:      8.0
 * Author:            STRYKE Marketing
 * Author URI:        https://www.strykemarketing.de
 * Text Domain:       stryke-wp
 * Domain Path:       /languages
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Update URI:        https://www.strykemarketing.de
 *
 * @package StrykeWP
 */

// Security: Block direct file access.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Runtime PHP version guard (header declares 8.0, enforce at runtime).
if ( version_compare( PHP_VERSION, '8.0.0', '<' ) ) {
	add_action( 'admin_notices', static function (): void {
		printf(
			'<div class="notice notice-error"><p><strong>STRYKE WP</strong> benötigt PHP 8.0 oder höher. Aktuelle Version: %s</p></div>',
			esc_html( PHP_VERSION )
		);
	} );
	return;
}

// ---------------------------------------------------------------------------
// Plugin Constants
// ---------------------------------------------------------------------------

define( 'STRYKE_WP_VERSION',  '1.1.1' );
define( 'STRYKE_WP_DIR',      plugin_dir_path( __FILE__ ) );
define( 'STRYKE_WP_URL',      plugin_dir_url( __FILE__ ) );
define( 'STRYKE_WP_FILE',     __FILE__ );
define( 'STRYKE_WP_BASENAME', plugin_basename( __FILE__ ) );

// ---------------------------------------------------------------------------
// Autoloader — must load before any class reference.
// ---------------------------------------------------------------------------

require_once STRYKE_WP_DIR . 'src/Core/Autoloader.php';
\StrykeWP\Core\Autoloader::register();

// ---------------------------------------------------------------------------
// Activation / Deactivation Hooks
// ---------------------------------------------------------------------------

register_activation_hook( __FILE__, [ \StrykeWP\Core\Installer::class, 'activate' ] );
register_deactivation_hook( __FILE__, [ \StrykeWP\Core\Installer::class, 'deactivate' ] );

// ---------------------------------------------------------------------------
// Bootstrap — fires after all plugins are loaded.
// ---------------------------------------------------------------------------

/**
 * Initialises the STRYKE WP master plugin.
 *
 * Hooked to `plugins_loaded` so that all WP APIs and other plugins are
 * fully available before we wire up our modules.
 *
 * @return void
 */
function stryke_wp_init(): void {
	// Shared services.
	$logger  = new \StrykeWP\Core\Logger();
	$options = new \StrykeWP\Core\OptionManager();
	$assets  = new \StrykeWP\Core\AssetManager( STRYKE_WP_URL, STRYKE_WP_VERSION );
	$cron    = new \StrykeWP\Core\CronManager();

	// Module registry.
	$registry = new \StrykeWP\Modules\ModuleRegistry( $options, $logger );
	$registry->register( new \StrykeWP\Modules\Connector\ConnectorModule() );
	$registry->register( new \StrykeWP\Modules\Branding\BrandingModule() );
	$registry->register( new \StrykeWP\Modules\Backup\BackupModule() );
	$registry->register( new \StrykeWP\Modules\WipMode\WipModeModule() );

	// Admin layer.
	$dashboard    = new \StrykeWP\Admin\Dashboard( $registry, $assets, $options, $logger );
	$menu_manager = new \StrykeWP\Admin\MenuManager( $registry, $dashboard );

	// Plugin meta (action links, row meta, plugins page styling, notices).
	$plugin_meta = new \StrykeWP\Core\PluginMeta( $assets, $registry );
	$plugin_meta->register_hooks();

	// Self-hosted update checker (STRYKE Hub API).
	$update_checker = new \StrykeWP\Core\UpdateChecker( $assets );
	$update_checker->register_hooks();

	// Boot the plugin.
	$plugin = new \StrykeWP\Core\Plugin(
		$logger,
		$options,
		$assets,
		$cron,
		$registry,
		$menu_manager,
		$dashboard
	);
	$plugin->boot();
}
add_action( 'plugins_loaded', 'stryke_wp_init' );
