<?php
/**
 * FixReport - Maintenance Logger
 *
 * Plugin Name:       FixReport - Maintenance Logger
 * Plugin URI:        https://www.code-admin.com/plugins/fixreport/
 * Description:       Log website maintenance tasks, errors, and updates, and generate PDF reports (Free Version).
 * Version:           1.0.1
 * Author:            Code Admin LTD
 * Author URI:        https://www.code-admin.com/
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       fixreport-maintenance-logger
 * Domain Path:       /languages
 * Requires at least: 5.8
 * Requires PHP:      7.4
 */

// Security: Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
	die( esc_html__( 'You cannot access this file directly!', 'fixreport-maintenance-logger' ) );
}

// Composer Autoloader
if ( file_exists( plugin_dir_path( __FILE__ ) . 'vendor/autoload.php' ) ) {
	require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
} else {
    add_action( 'admin_notices', function() {
        if ( current_user_can( 'manage_options' ) ) {
            echo '<div class="notice notice-error"><p>';
            esc_html_e( 'FixReport plugin is missing critical files required for PDF export (vendor/autoload.php). Please ensure Composer dependencies are installed correctly by running "composer install" in the plugin directory, or reinstall the plugin.', 'fixreport-maintenance-logger' );
            echo '</p></div>';
        }
    });
}

// Define Core Plugin Constants
if ( ! defined( 'FIXREPORT_VERSION' ) ) { define( 'FIXREPORT_VERSION', '1.0.1' ); }
if ( ! defined( 'FIXREPORT_PATH' ) ) { define( 'FIXREPORT_PATH', plugin_dir_path( __FILE__ ) ); }
if ( ! defined( 'FIXREPORT_BASENAME' ) ) { define( 'FIXREPORT_BASENAME', plugin_basename( __FILE__ ) ); }

// Load Activation and Deactivation Files
require_once FIXREPORT_PATH . 'includes/class-fixreport-activator.php';
require_once FIXREPORT_PATH . 'includes/class-fixreport-deactivator.php';

// Register Activation and Deactivation Hooks
register_activation_hook( __FILE__, 'fixreport_activate_plugin' );
register_deactivation_hook( __FILE__, 'fixreport_deactivate_plugin' );
function fixreport_activate_plugin() { FixReport_Activator::activate(); }
function fixreport_deactivate_plugin() { FixReport_Deactivator::deactivate(); }

// Load the Main Plugin Class
require_once FIXREPORT_PATH . 'includes/class-fixreport.php';

// Initialize the Plugin
function fixreport_run_plugin() {
    if ( class_exists( 'FixReport' ) ) {
	    $plugin = new FixReport();
        $plugin->run(); // Changed to a run method
    } else {
        add_action( 'admin_notices', function() {
            if ( current_user_can( 'activate_plugins' ) ) {
                echo '<div class="error"><p>';
                esc_html_e( 'FixReport plugin critical file (class-fixreport.php) is missing or corrupted. Please reinstall the plugin.', 'fixreport-maintenance-logger' );
                echo '</p></div>';
            }
        });
    }
}
add_action( 'plugins_loaded', 'fixreport_run_plugin', 10 );