<?php
/**
 * Plugin Name: ComptaFlow by MeeTempo
 * Plugin URI: https://comptaflow.meetempo.com
 * Description: Accounting entry assistant and data organization tool. Does not replace a certified accountant.
 * Version: 1.0.4
 * Author: MeeTempo
 * Author URI: https://meetempo.com
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: comptaflow-by-meetempo
 * Domain Path: /languages
 * Requires at least: 6.0
 * Requires PHP: 8.0
 */

if (!defined('ABSPATH')) {
    exit;
}

define('COMPTAFLOW_PLUGIN_FILE', __FILE__);
define('COMPTAFLOW_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('COMPTAFLOW_PLUGIN_URL', plugin_dir_url(__FILE__));

spl_autoload_register(function ($class) {
    if (strpos($class, 'ComptaFlowPro\\') !== 0) {
        return;
    }
    
    $relative_class = substr($class, strlen('ComptaFlowPro\\'));
    $file = COMPTAFLOW_PLUGIN_DIR . 'src/' . str_replace('\\', '/', $relative_class) . '.php';
    
    if (file_exists($file)) {
        require_once $file;
    }
});

// Load translations
add_action('init', function () {
    load_plugin_textdomain(
        'comptaflow-by-meetempo',
        false,
        basename(COMPTAFLOW_PLUGIN_DIR) . '/languages'
    );
});

// Load Dompdf for PDF generation
require_once COMPTAFLOW_PLUGIN_DIR . 'vendor/dompdf/autoload.inc.php';

// Boot the payments action controller
ComptaFlowPro\Admin\Actions\PaymentsActions::boot();

// Boot the PDF action controller
ComptaFlowPro\Admin\Actions\PDFActions::boot();

// Initialize the plugin
require_once COMPTAFLOW_PLUGIN_DIR . 'src/Bootstrap.php';
ComptaFlowPro\Bootstrap::init();
